DEV Community


Global Git Ignores

grahamcox82 profile image Graham Cox ・2 min read

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
  • Repository
  • 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
Enter fullscreen mode Exit fullscreen mode

And then editing the ~/.gitignore file. Mine looks like:

Enter fullscreen mode Exit fullscreen mode

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.

Discussion (3)

mhutter profile image
Manuel Hutter

To unignore something, add it to the local .gitignore file with a leading !

0xcmp profile image

Be careful with this. Sometimes when you're setting up new projects those files are already ignored, but won't be ignored for anyone else unless they also have a global ignore like yours. (And vice-versa and thing not meant to be ignored will be ignored)

Better to do on a per project basis

tpenguinltg profile image

According to the gitignore man page, the "default value [for core.excludesfile] is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead."

Forem Open with the Forem app