How to create a global .gitignore file

and forget to ignore the same files over and over again! ⚡️

Jesus Valera Reales
2 min readApr 25


Sometimes while we are creating a pull request, we realise we are committing some unnecessary config files, like the settings from your IDE, some cache files or even auto-generated files like the .DS_Store.

Fortunately, there is a way to ignore all these files in your system and don’t bother to add them anymore to every project in the specific .gitignore.

The first step is to create the global .gitignore file we are going to use.

touch ~/.gitignore

Depending on your SO, the IDE, the programming language, etc that you use, the content of this file could vary, but the idea is to place it here all these files you want to omit.


Finally, let’s add this file to your git as follows:

git config --global core.excludesFile ~/.gitignore

You can confirm your file was added by running the previous command without specifying the path.
You should see the file location, if so, it should be done 🐙

git config --global core.excludesFile

/Users/Jesus/.gitignore # Output 👀

If you are not working alone on a project, consider that maybe other people are not ignoring the duplicate files globally as you do, so for this, it is worth adding these lines not only on your global but in the .gitignore from that project.

Happy programming! 🤓



Jesus Valera Reales

Competitive, entrepreneur and autodidact. Hard worker, lover of technology and free software.