How to set a global .gitignore

This article was published on May 26, 2021, and takes approximately a minute to read.

Let's say you want to have a folder or a file for EVERY project but you don't want to commit it.

For me, these are 2 things:

  • .tool-version - file from asdf which species the node version for the current project (e.g. nodejs 12.13.1)
  • .history/ - folder generated by the Local History extension for VSCode where it generates a copy of a file so I'm able to rollback if I need

All I need to do to avoid adding those 2 entries everywhere is:

Create and open a gitignore file in my user root dir:

code ~/.gitignore

Add the content I want:

.tool-versions
.history/

Set it in global config:

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

And that's it. For every project I have git, it will never suggest to commit these two entries:

Resources