Defining a global .gitignore file

A .gitignore file should only contain files and directories related to the actual project/package, no environment-specific stuff. If multiple people are working on a project, all of them using different IDEs or operating systems, there are potentially dozens of files or directories that have no place in the repository. Not to mention you’d have to update each project’s .gitignore file if you start using a new IDE that nobody has used before.

The best way to go is to create a personal, global .gitignore, which is very easy. Create your global file:

touch ~/.gitignore

Edit it, add some stuff that should be globally ignored (e.g. .DS_Store, /.idea/…) and then run:

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

Done! Easy as pie! Everything listed in there will now be globally ignored in any repository you work in. No more messy .gitignore files.