Today I learned that I can have a global .gitignore file, so I don’t have to create one for every project.
According to git documentation, some of the sources that git uses to find patterns to ignore are:
- The .gitignore file we all know and love.
- And patterns in the file specified by core.excludesFile configuration variable.
Note that the local
.gitingorefile will always be more prioritized than the global one. (i.e. if a file is ignored in the global.gitignorefile, but explicitly tracked in the local.gitignorefile, it will be tracked, and vice versa)

The file my.file is ignored globally but explicitly tracked locally, so it will be tracked.
Using the global git config, we can create a global .gitignore file that will be used by git to ignore files and directories across all projects.
touch ~/.gitignore # or any other file nameThen we can add patterns to ignore in this file, for example:
echo "*.log" >> ~/.gitignore # Ignore all log filesFinally, we need to set the core.excludesFile configuration variable to point to the file we just created:
git config --global core.excludesfile ~/.gitignoreAnd voilà, we have a global .gitignore that will be used by git across all projects.
Bonus: The gitignore.io website is a great resource to generate
.gitignorefiles for different projects and languages.