Over a million developers have joined DZone.

How to Create a Global .gitignore File

DZone's Guide to

How to Create a Global .gitignore File

· DevOps Zone
Free Resource

Download “The DevOps Journey - From Waterfall to Continuous Delivery” to learn learn about the importance of integrating automated testing into the DevOps workflow, brought to you in partnership with Sauce Labs.

GitHub encourages you to include a .gitignore file with all of your repositories to specify which files should not be tracked. If you're not looking for it, though, you may not be aware that you can create a global .gitgnore, which will keep certain files or file types from being tracked in any of your projects (in addition to whatever project-specific rules you include in individual .gitignore files). It's useful for things like .DS_Store on OSX (which keeps track of your folder settings) that you'll probably never want to include in any project.

First, create a .gitignore file that you'll use for all of your projects - you'll probably want to put it in your root directory. In their instructions, GitHub suggests:


Then, in the terminal, use this command to designate the .gitignore you created as global:

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

Keep in mind that the command above assumes you named it .gitignore_global.

If you're not sure what you'd want to exclude, octocat has provided a list of common exclusions that might give you some ideas. You don't want to get too trigger-happy with global exclusions, though - stick to things you're fairly certain you'll always want left out, or else you might forget something relevant down the line. The OS generated files octocat mentions are particularly likely choices:

Once you've run the command and added your exclusions, the files and file types you specified won't be tracked in any of your Git repos!

Discover how to optimize your DevOps workflows with our cloud-based automated testing infrastructure, brought to you in partnership with Sauce Labs


Opinions expressed by DZone contributors are their own.


Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.


{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}