I feel like I’m looking up how to do things in Git more often than anything else. It’s all sunshine and roses if all you do is make changes, commit them, and solve a few merge conflicts here and there. But if you need to do anything more specific, like say, not commit sensitive info into a public repo, then the Googling starts. And there are usually a few ways to do it, most of them super complicated, involving multiple scripts and ritual sacrifices that require to be performed on a full moon night. Cause we all know github truly runs on souls.
Anyway, here’s a list of a few easy commands that I found after plenty of Googling and coming dangerously close to losing my soul:
Situation: You want to commit a config file with a bunch of settings, one of them being a private key of some sort, but you do not want to commit the key. You also don’t want to have to remember to remove the key from the file before every commit because why the hell would you want to do that.
Solution: Add all of the settings to your file, including the key, and assign a dummy value for the key, something like YourKeyGoesHere. Then commit as normal. Now run the following command in git
git update-index --assume-unchanged filename – This command tells git to ignore any changes made to that particular file.
Now add in your real key and resume working on your app. If later on, you need to make changes to the config file and you want those changes checked in, just run
git update-index --no-assume-unchanged filename. This will remove the file from the ignore list and allow you to check in changes. Just remember to replace your key with the dummy key, else all of this was for naught.
Note: There are a couple of commands that can undo the ignore: stash and reset are the ones I am aware of so far.
Credit for this simple solution goes to this StackOverflow post