Ignoring project files in git

Bookmark and Share

Over and over again, I have the need to synchronize files between my home computer, my office laptop, and possibly other computers as well. I use git because a lot of these files are things that I might conceivably want to keep a history of, and also because git makes it easy to set up a work environment on another computer.

Project metadata files get in the way of this, though. These are the files that fancier editors use to keep track of things like which files you had open, what syntax highlighting schemes you were using, and so on. The file typically gets changed every time you open the editor. Now, most of that information is pretty trivial, and I typically don’t want to synchronize it between computers or keep track of its history. On the other hand, when I’m setting up on a new computer, it’s pretty handy to have a project file available to start with, so I’m reluctant to exclude the files from the archive entirely.

Today, I found a solution. After you clone your git repository, in the new work environment, run

git update-index --assume-unchanged <projectfile>

This sets a flag which tells git that it should ignore anything that happens to <projectfile>, and just assume it never needs to be committed. That way, git will just ignore the project file when determining whether you have uncommitted changes, and it’ll report that your working copy is up to date as long as all your other files (the ones you actually care about) are up to date.