Every directory on macOS gets a .DS_Store file to tell Finder how it should display it. 99% of the time we don’t want to include .DS_Store files in our repositories so we add .DS_Store to our projects .gitignore file.

What if we could globally ignore .DS_Store rather than adding it to every repository’s .gitignore file?

core.excludesfile

Git allows us to specify a global gitignore file via the variable core.excludesfile.

Global .gitignore

Create (and populate) your global gitignore file. In my dotfiles repo I’ve called mine .gitignore_global then symlinked it into my home directory as .gitignore.

ln -s /Users/0xmachos/Documents/Projects/dotfiles/.gitignore_global /Users/0xmachos/.gitignore

Tell Git About It

Tell Git about it via one of the following methods:

Execute the following:

git config --global core.excludesfile ~/.gitignore

Or add the following to your .gitconfig:

excludesfile = ~/.gitignore

You no longer have to add .DS_Store to every project’s .gitignore file.

Group of 7 Border Collie puppies on a step, some of them sleeping Photo by Jametlene Reskp on Unsplash