Read more

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

Arne Hartherz
May 06, 2013Software engineer at makandra GmbH

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

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

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
Posted by Arne Hartherz to makandra dev (2013-05-06 18:08)