There are some files that shouldn't be tracked by Git at all. For example, the temporary files created by the text editors, the Python bytecode, and etc.
How could we ignore those files? In the previous post, I have mentioned
that we can create a .gitignore
file and list the name patterns to be
ignored. However, the .gitignore
file is managed by Git and should
be version controlled. It will be cumbersome to create .gitignore
files for all repositories.
Is it possible to create a global .gitignore
file for all Git
repositories? Yes, of course we can. We can create a ignore
file in
$HOME/.config/git/ignore
and the listed name patterns will be ignored
globally.
For example, if we wish to ignore the *.swp
files created by Vim,
we can use the following commands:
$ mkdir -p ~/.config/git
$ echo '*.swp' >> ~/.config/git/ignore
After these commands, Git should start ignoring the swap files.
Change the Global Ignore File Path
Under some circumstances, we may wish to change the file path to the ignore
file. We do so by setting core.excludesfile
.
For example, to change the ignore file path to ~/.gitignore
:
$ git config --global core.excludesfile ~/.gitignore