Logo Devoh

Global .gitignore

Git is really good at keeping a perfect history of the changes to your files. That's a great quality to have when those files are code, but not so great when a bit of application configuration slips in.

Here are some things you probably don't want in version control:

  • API keys and secret tokens for external services
  • environment configuration unique to a developer's particular computer
  • editor-specific files (e.g. *.swp Vim swap files)
  • OS-specific files (e.g. .DS_Store on OS X)

It's common to add these sorts of things to the project's .gitignore file, but I often find I'm ignoring the same files over and over again as I start on new projects. This is where the global .gitignore comes in. It acts just like the per-project .gitignore files, but it's automatically picked up by every repository.

Do this right now:

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

No really… I'll wait.

Now, the .gitignore file in your home directory acts just like the .gitignore files you're used to in the repositories, but it applies equally to all your repos. I wish Git enabled this out of the box, because I think the feature would get a lot more use if that were the case.

My ~/.gitignore

These are some of the entries in my global .gitignore that you might want to add to yours:

# Mac OS X hidden files
.DS_Store

# Vim swap files
.*.sw?

# Pow and Powder config
/.pow*

# RVM and rbenv
/.rvmrc
/.rbenv-version

# Bundler binstubs
/bin/

Additional Resources

  • The gitignore(5) man page has some details on the pattern format and globbing used in .gitignore files.
  • GitHub has a nice writeup on ignoring files, which also includes a useful bit about excluding files from individual repos.

More to Come

I want to start to documenting the development practices that I find useful, in the hope that they might also be useful to you. It's something I've been thinking about for a while now, and what better time to start then the beginning of a new year? This is the first in what I hope will be a series of similar posts with the tips and tricks that have become habits for me.