I often find that I want to make local changes in configuration files that have been checked-in to Git. For instance, I find that the database.yml has been checked in to a Rails project, and I need to override the MySQL port or password. Or the Gemfile contains OSX-only that won’t install on my Ubuntu machine.
I could quibble with the project members about doing things “right” and keeping system-specific settings out of Git. But part of my job as a consultant is to fit in with project conventions unless there is a compelling reason to argue for a change. So I’ve been wondering if there is a non-disruptive way to keep long-lived local changes without them constantly showing up in “git status” listings.
It turns out, the magic words are:
git update-index --skip-worktree FILENAME
Where “FILENAME” is the name of the file I want to keep local changes in.
There’s a matching “–no-skip-worktree” to flip that bit back off.
With this bit set on a file, local changes to the file will not show up in git status listings.
A lot of people pointed me to the similar “–assume-unchanged” option. However, my (brief) reading of the relevant manpage seems to suggest that “–skip-worktree” is more closely aligned with what I’m trying to do. If anyone can shed more light on the difference between the two settings I’d be grateful.