Global gitignore vs repository gitignore

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.

# NetBeans
# TextMate
# PHP Storm, other java IDE's
# OS X
# Windows

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
Tags: #git
Thomas Hunter II Avatar

Thomas is the author of Advanced Microservices and is a prolific public speaker with a passion for reducing complex problems into simple language and diagrams. His career includes working at Fortune 50's in the Midwest, co-founding a successful startup, and everything in between.