Global gitignore vs repository gitignore

Multithreaded JavaScript has been published with O'Reilly!

Most people are aware of the .gitignore file which can be placed in the root of your git repository. This file can contain a list of files specific to the project which shouldn't be committed into the repository. This file should be used for ignoring files which your project generates, such as build and temp type directories.

However, a lot of people don't know that you can place a similar file in the root of your home directory. This file affects every repository you use on your machine. Some of the perks to using this file is that you dont need to commit it, and making one change affects all of your repositories. This global file should be used for putting in files specific to your environment. For example, if you are on a windows machine using Netbeans, you would want to add Thumbs.db as well as nbproject. Since other people using the repositories won't necessarily be using the same setup, they wouldn't benefit from having your specific ignores in the repo's gitignore.

Here's a list of example entries you can put into your global gitignore file. You'll only want to put the ones in there that matter to you.

# VIM
.*.swo
.*.swp
tags
# NetBeans
nbproject
# CVS
CVS
.cvsignore
# TextMate
.#*
# PHP Storm, other java IDE's
.idea
# OS X
.DS_Store
._*
# Windows
Thumbs.db

If you'd like to check out a more comprehensive list, check out GitHub's gitignore list.

UPDATE: If you are running the GIT which ships with OS X, the global .gitignore file isn't used by default. To fix this, issue the following command (you may need to run it in certain *nix environments too, I'm not positve).

git config --global core.excludesfile ~/.gitignore
Thomas Hunter II Avatar

Thomas has contributed to dozens of enterprise Node.js services and has worked for a company dedicated to securing Node.js. He has spoken at several conferences on Node.js and JavaScript and is an O'Reilly published author.