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 web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
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)