Properly excluding IDE-specific files with Git

 Posted by on November 5, 2012  General  Add comments  Tagged with:
Nov 052012

We’re all familiar with the various project-related files that are thrown into our working directories by IDE’s and the various tools we use.

It’s very tempting to just start throwing things like .settings/, .idea, .project/, etc into the project’s .gitignore file as you run across them, and unfortunately, many projects do this. However, Git provides a much more elegant solution for this: global excludes files.

It’s incredibly simple to set up:

[user@workstation ~]$ git config --global core.excludesfile ~/.gitignore_global

Now, create a .gitignore_global file in your home directory and add the files and path so all of your IDE-specific files that you want to keep out of your git repositories. This way, these files are always automatically ignored for every project you’re working in on, without having to pollute each project-specific .gitignore.

(If you are a Windows user, please do the world a favor and immediately add Thumbs.db to your newly-created .gitignore_global. Mac users, do the same for .DS_Store. Thank you.)

You should reserve the project .gitignore file for files that are actually specific to the project such as cache and log files resulting from the project being ran, and use the global excludes file for any files that are specific to your own development environment.

There are some of those who will argue that putting these common IDE files in the project’s .gitignore helps to lower the barrier-to-entry for contributors by preventing accidental commits of these meta files, and that there’s no harm in them being there. While there is some truth to that, I can say from experience that this is rarely actually a problem in practice (especially if it’s documented in a contributor guide). On the rare occasion it does come up, I stand by the principle that it’s better to spend a minute or two to educate the contributor on properly ignoring these files, which will likely help them avoid mistakes in future projects which may not have such files already ignored for them (or maybe just not the files for that particular IDE or version of that IDE).

Note: If you want to ignore a file or path in a single project (not globally), but it’s still not something that’s appropriate for the project’s .gitignore, you can put it in projectpath/.git/info/exclude. This file works like a .gitignore in your project root, except it is not actually committed to the project; it simply stays with your local clone of the project.

  3 Responses to “Properly excluding IDE-specific files with Git”

  1. Great tip Evan!

    Ive used .gitignore wihtouth knowing there is a better way.

  2. While relying on a global .gitignore for scripting language projects is doable – frankly it’s asking for trouble on anything compiled

    No you CANNOT expect anyone trying to contribute to remember every single stupid file that autotools (or XCode, or Visual Studio) throws into your directories during configure and compile steps – and they often change from version to version which makes it even more of a PITA

    If you haven’t experienced the issue in projects you work on, I’m pretty sure you haven’t worked on a compiled language project ;)

 Leave a Reply



You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" color="" escaped="">