Setting up a global .gitignore on Mac and Windows

Using a .gitignore file can be very useful. It is used to ignore certain files on specific projects. But what should you do if you find yourself consistently creating a .gitignore for the same files on every project? Create a global .gitignore!

What are some examples of files that you would want to ignore on every project? I have listed just a few below:

  • .DS_Store
  • Thumbs.db
  • .log
  • .sql
  • .sass-cache/
  • .codekit-config.json

Create and set the .gitignore

Create a typical .gitignore containing the files you want to ignore and name it whatever you want, typcially .gitignore_global, and put it wherever you want, typically at ~/. Once you have done that then type the following command into terminal:



That’s it! Enjoy not sending thousands of .DS_Store files to your repo. It’s probably the most annoying thing about using Mac.

Example of a global .gitignore

Here is an example of my own personal global .gitignore. You may want to add or remove some of the things on it to better suit your needs.


, , , , , ,

8 Responses to Setting up a global .gitignore on Mac and Windows

  1. Joe Astuccio April 24, 2014 at 5:17 am #

    Terminal gave me the error ‘key does not contain a section: –global’ Typing two – infront of global seems to have fixed it.

    git config –global core.excludesfile ‘PATH/.gitignore_global’

    This post was still very helpful for setting up my global gitignore. Thanks.

    • Alex Fernandez April 29, 2014 at 9:19 pm #

      Very interesting. WordPress was taking my double dash and turning it into a single. Thanks for the catch Joe! I have entered the commands into a code like style so that doesn’t happen.

      Glad I could help!

  2. KenJazzyJones July 15, 2014 at 2:04 am #

    Bro! Ima do this tomorrow!

  3. KenJazzSauce August 1, 2014 at 3:36 pm #

    I done did it! Life HP points leveled up!

  4. gurcan October 7, 2014 at 8:17 pm #

    thanks for tips 🙂

  5. samizdam December 5, 2014 at 11:53 pm #

    hm… on win7 for me work it:


    but not work


  6. Michael Freidgeim March 2, 2016 at 5:34 am #

    Please update the article with ~/.gitignore_global, as %USERPROFILE% seems doesn’t work

Leave a Reply