Wednesday, January 14, 2015

Ignore files without modifying .gitignore

Brief note: Thanks to this episode of the Ruby Rogues featuring John Sonmez, I've been inspired to blog a little more often.

Problem: You use git and might use some tools that generate files that other people on your team don't use.  For example, you might use vim and create a Session.vim file.  Rather than clutter the .gitignore with these files, there is another elegant solution.

Solution: You can put these entries into .git/info/exclude and git will ignore them, just as if you had placed them in .gitignore.  There is one difference, however: .gitignore is usually committed, but .git/info/exclude is a file that exists in your working copy of the repo and it is not committed.  Therefore, if you clone the repo to another location on your computer, you'll have to add the entries to .git/info/exclude again.

There are advantages and disadvantages to each method -- don't fret about it too much though.  You can always revert your changes and try the other technique.