Chances are most of the Git repositories you work with contain a
file. This tells Git the files and directories that you want kept out of
.gitignore file is usually programming language or framework specific, and
is a great way to keep the repository clean and free of things like log files
and build artefacts.
What it‘s less good for, however, is ignoring files that are specific to your
particular operating system, IDE, or environment. Firstly, it‘s a pain to have
to add your own system-specific exclusions to the
.gitignore file of every
repository you work with, but also it makes for a messy
especially when there are many developers all with their own particular set-up.
Thankfully there is a simple solution: maintain your own global ignore file which will apply to all the repositories you work with on your computer.
Configuring a global Git ignore file
From your terminal or command line, run the following to configure Git with a
global ignore file called
.gitignore_global in your home directory:
$ git config --global core.excludesfile ~/.gitignore_global
Now you can fill it with all the system-specific exclusions you like, without polluting the ignore files of the repositories you work with.
What to add to your global Git ignore file
My global ignore file contains operating system specific things like macOS’
.DS_Store file, but also things specific to my IDE, for example the
file generated by Ctags.
For a comprehensive library of operating system and editor specific exclusions check out the community-maintanted github/gitignore repository on GitHub.
There is a third way…
Sometimes you may have a file you want to exclude from a repository that doesn’t
belong in the repository’s ignore file, but also doesn’t belong in your
global ignore file. In those probably rare cases, you can list the exclusion in
a file in your local repository called
More articles on Git