Global .gitignores for All!

Pixelated Andrew Pixelated Andrew
~2 min read

I’m not a big fan of the word “should”, but if you use Git and don’t have a global .gitignore file, you should.


$ git config --global core.excludesfile ~/.gitignore_global

~/.gitignore_global can be called whatever you want.

Global ignore files work exactly like project-specific ignore files except that they apply to every repo on your local machine! You should now fill it up with all the generic files created by your operating system, your editor, or by you yourself that litter your file system.

For example:

# ~/.gitignore_global

.sw?    # Vim's .swp, .swo,
.*.sw?  # and .swn backup files


A project’s .gitignore can serve to document any by-products its system spits out while running on your local machine—Polluting it with files specific to your OS and editor hurts this as these files have nothing to do with the project itself. It also saves you from having to make an ignore file for every new repo you create on your machine, which I think is pretty nice. Finally, if you want to contribute to open source it’s pretty much required to maintain a such a file—You could imagine that project maintainers who are getting contributions from a wide variety of OSs and editors aren’t going to want to maintain a monster ignore file.

So that’s it?

Yep, that’s it. Creating a global .gitignore is a small piece of advice that probably won’t change your life too much. Maybe you aren’t feeling the pain and that’s perfectly legit!

But I still think you should have one.