Make git ignore local changes to tracked files
Sometimes you want to change a tracked file so that you can run your project locally on your machine. This is typical of configuration files and templates. But you don’t want to commit these files. One way is to discard these changes every time you are about to commit and redo them every time you pull from master. Another way is to stash them before you commit and reapply them after you pull.
But there is a better way! You can tell Git to ignore changes to this file:
Now you can go ahead and do whatever you want in that file and it will not show up as a changed file in git.
This will work unless that file is changed on the remote branch. In that case if you do a pull, you will get an error.
When that happens you need to tell Git to start caring about the file again, stash it, pull, apply your stashed changes, and tell Git to start ignoring the file again:
You can automate this by either creating a bash script or a Git alias that does all these steps at once.