Take me home

Global gitignores

Published June 25, 2009

On Mac OS X, the Finder creates a .DS_Store file in all the directories it displays. If you happen to browse your git repository with the Finder, you’ll get these files in your repo, and they’ll show up as untracked files in git status. A common workaround is to add .DS_Store to the .gitignore. Here’s one of my gitignore files for a Rails project:

.DS_Store
*.log
*.sqlite3
config/database.yml
db/schema.rb
tmp/**/*

I have a slight problem with this, though. The .DS_Store isn’t related to your project, it is related to the system you’re coding on. Yor .gitignore file will be a lot more elegant if it only lists files that are related to the projects. For a Rails app, log files and db/schema.rb is definitely app related. .DS_Store isn’t, though.

This is why I have a global gitignore file for my system, that ignores system related files.

> git config --global core.excludesfile ~/.gitignore

This file contains the following:

.DS_Store

And voila, you no longer have to add .DS_Store to all your .gitignore files.


While this article might seem OS X specific, it applies to all systems. A good example is thumbs.db on Windows systems. I’m sure some Linux distros has similar system files. Global gitignores are not limited to .DS_Store on OS X, but all system files that shouldn’t be allowed to sneak into your repositories or your .gitignores.


Questions or comments?

Feel free to contact me on Twitter, @augustl, or e-mail me at august@augustl.com.