Steven Wake

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

Comments: 1

Gareth
commented on

Remember if you're sharing your project with any other users (as is common with git repositories) that a global gitignore file is specific to your system. It won't stop any other users from adding those files into your repository. If you really need those files never to be committed then you'll need a project .gitignore file too

Add a comment

Note: comments are moderated before publication.

Most Popular

Garmin Edge 705 Data Recovery with DD & XML

Joel Richards

After recently taking part in a race across Scotland, using a Garmin GPS device (Edge 705) I had around 12 hours of GPS data which unfortunately seemed to get corrupted during the ride. The device was properly displaying the data on the unit, but Windows, OSX and Linux were all …

Web Meet Guildford is back

Paul Sturgess

After the resounding success of the first Web Meet Guildford (WMG) we’re excited to announce that we’ll be hosting another meetup later this month. So if you make websites and you live or work in the Guildford area, please do join us in the 3 Pigeon’s pub on Guildford High Stree…