Global Git Ignores
Graham Cox Jan 20 '17
This is a feature that I find invaluable, but that I don't recall seeing a huge amount of documentation on at the time I started using it. (Turns out it is in the official documentation, but only as a tiny section)
Git has the ability to configure a set of files that it should just ignore. You can do this at three different levels:
- Local working copy
- Local Workstation
The first of these is done by editing the
.git/info/excludes file in your checkout. This allows you to have certain files in your local working area that you want to have ignored, but you don't want to commit this ignoring to the repository for everyone. Maybe it's IDE project files for the IDE that only you use, or maybe you have a habit of keeping .org files in your working area. It doesn't really matter.
The second is done by editing the
.gitignore files anywhere in your checkout and then committing them. This gives rules that apply to the repository as a whole, not just to your checkout of it. Maybe it's build artifacts, for example.
The third is less obvious, but is essentially the same as the first one but applying to every repository on your machine. This is done by first executing:
$ git config --global core.excludesfile ~/.gitignore
And then editing the
~/.gitignore file. Mine looks like:
.DS_Store .*.swp *.iml .idea
Excluding the Mac .DS_Store files, the Vim swap files, and the IntelliJ project files.
The one downside to this is that I've no idea how to un-ignore something on a more local scale, though to date that has never been an issue.