For whatever reason, sometimes we find ourselves in these “pickles” where we need to delete a file in our Git repo but we don’t want the file to be deleted when others pull from the server. Better said, we want to untrack files from our Git Repo.

The answer to your problems is:

# Do this on all machines echo "FILE_NAME" >> .gitignore git rm --cached FILE_NAME git add -u git commit -m "removing files from version control" # Sync with your git server, pull to sync and push to register your local change git pull git push

Scenario

Your Git repo is in full play. Developers have it in their workstations and the initial pull is now on production and development servers. Everyone has changed setting in their config file to match their local machine, same on production and development, but no one wants to push those changes. AHH! We need to untrack this file(s).

Don’t Delete

What you DON’T want to do is delete the file git rm FILE_NAME . Doing so will have a ripple affect on everyone’s next pull from the git server.

Solution

Add the filename to your .gitignore file (if you don’t have one, create it). This will make sure git ignores changes to this file(s) for all future commits. Remove the HISTORY of the config file(s) not the file itself. This causes git to have amnesia about the existence of your config file(s)

echo "FILE_NAME" >> .gitignore git rm --cached FILE_NAME git add -u git commit -m "removing files from version control" git pull git push

Repeat these steps on all your machines.

Don’t let that last git pull and git push throw you off! The first git pull is to sync anyone else’s commits who “removed” cached files before you. The git push tells the server that you are also ignoring the config files.

Resources

Feel free to download the diagrams: Google Docs Drawing

Below is a code snippet I used. Given that all your config files end in “.config”, this could work for you too. You can also use this technique to untrack unit tests, SQL or other files.