Set up a global .gitignore file

A global gitignore file can be handy to automatically hide common files from projects that you work on. I typically use this for files that are specific to me and my local setup. First create the file that you want to use for your global .gitignore file.

Published on

Written by David Peach

A global gitignore file can be handy to automatically hide common files from projects that you work on. I typically use this for files that are specific to me and my local setup.

First create the file that you want to use for your global .gitignore file. I just use a file called .gitignore in my home directory.

touch ~/.gitignore

Then run this git command to make all git repos you work with use your global .gitignore as well as the project specific one.

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

Then add filepaths to your new global file as you would a project-local one.

My use case.

I use Neovim, BTW. As part of my setup I have some project-specific settings that can be set by adding a file name .exrc into the project root. Of course I don’t want this committed to the repo, and it doesnt make sense to include editor-specific ignored files to the project gitignore. So I add that file to my global .gitignore.

Tags Git Programming Terminal