0

I don't want to commit my changes on git, but I want to keep the changes locally.

Means there are changes that are needed on my machine only, so I want to keep the code on my machine but I want to commit these codes on the git.

How can do this?

Please help me out on this.

Antonio Petricca
  • 8,891
  • 5
  • 36
  • 74
  • Hi, I have a hard time understanding how to make sense out of these two sentences : "I don't want to commit my changes on git, but I want to keep the changes locally. [...] so I want to keep the code on my machine but I want to commit these codes on the git". Can you please rephrase your question ? also : can you explain what kind of changes you want to "keep locally" ? is it something like local configuration ? – LeGEC Sep 06 '21 at 09:09
  • very simple, suppose you have made changes in some files but these changes are needed only for your machine so you wouldn't want to push these changes but it should be in your local git. Actually, I want to ignore these changes when using git status –  Sep 06 '21 at 09:37
  • Is it a hack in your code ? like : on your machine, you want to have `int security_check() { return 1; }` in the middle of your `auth.c` file ? or a set of settings ? like : a separate `config.json` file relevant only to your machine ? – LeGEC Sep 06 '21 at 09:41
  • You don't want to ignore the changes; you just want to keep them in a separate branch that is never merged into the main development branches. – chepner Sep 06 '21 at 13:37
  • However, this probably indicates something that should be a configuration option, not something that's hard-coded. – chepner Sep 06 '21 at 13:38
  • Does [this answer](https://stackoverflow.com/a/23532748/1290731) help? – jthill Sep 06 '21 at 15:12

1 Answers1

1

This is a specific instance of the more general question, “How do I ignore tracked files in Git?” which is answered in the Git FAQ:

Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.

It’s tempting to try to use certain features of git update-index, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.

If you're working with configuration files, the Git FAQ has more to say about that:

If your goal is to modify a configuration file, it can often be helpful to have a file checked into the repository which is a template or set of defaults which can then be copied alongside and modified as appropriate. This second, modified file is usually ignored to prevent accidentally committing it.

You can use similar approaches for other types of situations as well.

bk2204
  • 64,793
  • 6
  • 84
  • 100