Mike Rogers on a Snowmobile

How to setup a global .gitignore

Posted on

The .gitignore file is really handy for stopping silly system files (like that pesky .DS_Store fella) from entering your git repository. However, did you know you can setup a global .gitignore that'll apply across your system?

What to run in Terminal

It's pretty easy to set up a global .gitignore, simply just create a file containing your common .gitignore items and put it somewhere easily accessible on your system, then run in terminal:

git config --global core.excludesfile 'PATH/TO/YOUR/.gitignore'
View on Gist Github

Amending the 'PATH/TO/YOUR/' with the path to your .gitignore.

Example global .gitignore

This is an example of the global .gitignore I use of my current system:

# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so

# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip

# Logs and databases #
######################
*.log
*.sql
*.sqlite

# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
View on Gist Github

This was written by Mike Rogers, a freelance Ruby on Rails developer based in London.

Share the ♥ by sharing this!

If you want to discuss this post, feel free to tweet me (@MikeRogers0) or drop me an email. Any code samples unless stated otherwise are licensed under the The MIT License (MIT). Spotted a mistake? Send me a pull request :)