Global Git ignore
A handy little feature of Git is the global ignore file. Use this file to exclude annoying system files from your nice clean repo, especially good for those dreaded .DS_Store files (Mac poo) on OSX and Thumbs.db files on Windows.
Setup and configuration of a global ignore file is extremely simple:
1. Create a text file somewhere on your system. I would recommend your home directory. Name the file whatever you choose. As a configuration file I would recommend starting the file name with a “.” in order to hide it. I named my file “.gitignore_global”
2. Populate your file with patterns you wish to ignore in your repos. You probably want to start with the following 2 main offenders:
Thumbs.db
*.DS_Store
I develop Cocoa apps using Xcode so I added the following as well:
*.xcuserstate
project.xcworkspace/
xcuserdata/
3. Fire off the following command at the terminal, replacing the path at the end for the path to the your ignore file:
git config —global core.excludesfile ~/.gitignore_global
That was easy wasn’t it!
Two final tips to consider when using a global ignore:
1. Ignore files do not remove files that match your patterns. If you add a pattern after the fact, you will need to use Git rm to remove them.
2. Tread carefully. Being too heavy handed with a global ignore file may lead to head scratching and wasted debugging effort
Tags: git
Tweet