I always liked the idea of not polluting your project’s .gitignore file with something unrelated to the project itself. Now, this can be anything, from OS-specific generated files like .DS_Store, thumbs.db to editor-specific files like .vscode. While there is nothing wrong with adding these to the project’s .gitignore files, I feel like the better place to put these rules are in a global .gitignore file.

The file can be set via the core.excludesFile configuration variable in Git, which will be included in addition to the other .gitignore that you’ve set in your project. Pretty useful!

To get started, create a dedicated file that you want to use as a global .gitignore. In my case, I decided to name it .gitignore-global.

1
touch ~/.gitignore-global

Then, in the file itself, you can add any patterns that you usually would add to the project’s .gitignore. As for me, these are the patterns I currently put in:

.DS_Store
.idea
.log

Lastly, set the core.excludesFile Git configuration to point to that file, like:

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

That’s it!