Quick Tip: Git Global Exclude File

One of my Vim plugins generates a .cache directory in every project. Instead of telling every git repo to ignore it, use the system-wide exclude file.

Quick Tip: Git Global Exclude File

This autumn I’ve completely switch over from using VScode to using Vim (neovim, to be specific). The adventure has included solving myriad small annoyances and this evening I just squashed another one.

I’m using Conqueror of Completion Vim extension. Since I’m working mostly in C, I’ve installed clangd as part of this and it dumps a .cache folder into each directory I’m editing. My initial reaction was to add the directory to the Git ignore file, but that gets old really quickly. This evening I discovered you can ignore file system-wide by using git’s core.excludesFile settings.

How to use Git’s core.excludesFile

Git’s core.excludesFile works the same way as any .gitignore file. Just add the filename/directory patterns you want to ignore. The difference is that you need to tell git where your system wide file is. Here’s my ignore file:

.cache

With that in place, just set the value using this git command:

git config --global core.excludesFile '~/.gitignore'

Now it looks like the home directory is the recommended location for this, but I ended up moving it to my dotfiles repo so I can share the file between systems.

Checkout the gitignore docs page for more on this handy feature.

essential