Use a global .gitignore file to ignore stuff from your machine

Sometimes you want git to ignore certain files that appear on your machine. You can do this in 3 ways:

  • Per project, in the project's .gitignore file
  • Per project, in a local exclude file
  • Globally on your machine

Downsides of per-project .gitignore entries

While it might be tempting to set it per project (other devs might benefit from it), you

  • need to do it each time for every project
  • "pollute" a project's .gitignore file with stuff that may be quite irrelevant for others

A global ignore file for the rescue

You can just put your patterns into another file, in your home directory on your machine (e.g. ~/.gitignore).
Then, just feed it to git:

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

The file's effect will apply immediately if you do that from a repository. Neat.


Use cases for global ignores

  • you're using a special editor that creates a hidden directory for config (e.g. VS Code)
  • ignore a dir called untracked for your personal code snippets or project files like Excel sheets
Arne Hartherz Almost 11 years ago