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
.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:
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
(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.