Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Global gitignore

There are certain files created by particular editors, IDEs, operating systems, etc., that do not belong in a repository. But adding system-specific files to the repo's .gitignore is considered a poor practice. This file should only exclude files and directories that are a part of the package that should not be versioned (such as the node_modules directory) as well as files that are generated (and regenerated) as artifacts of a build process.

All other files should be in your own global gitignore file. Create a file called .gitignore in your home directory and add anything you want to ignore. You then need to tell git where your global gitignore file is.

Mac

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

Windows

git config --global core.excludesfile %USERPROFILE%\.gitignore

This will result in an entry in your .gitconfig that looks like this:

[core]
    excludesfile = {path-to-home-dir}/.gitignore

Global .gitignore contents

Depending on your OS and tools, the following contains sample of what you might want to include. When you run git status before adding any files to your local repo, check to see if any files don't belong. Add them to your global gitignore as appropriate.

# Node
npm-debug.log

# Mac
.DS_Store

# Windows
Thumbs.db

# WebStorm
.idea/

# vi
*~

# General
log/
*.log

# etc...

WebStorm

If you use WebStorm, you will also need to copy your global gitignore contents to its Ignored Files dialog.

Mac

WebStorm | Preferences | Version Control | Ignored Files

Windows

File | Settings | Version Control | Ignored Files

@liukun

This comment has been minimized.

Copy link

commented Jan 4, 2018

According to https://stackoverflow.com/a/22885996 , you can just edit ~/.config/git/ignore .

@ElMatella

This comment has been minimized.

Copy link

commented Mar 21, 2018

Cool, that works great! Ideal for the DS_STORE mac file and eventually the .idea folder generated by all the Jetbrains IDEs

@markwartman1

This comment has been minimized.

Copy link

commented Apr 1, 2018

So, a list much longer like Octocat has generated, is that list something to put in my own global gitignore file?

@randallb

This comment has been minimized.

Copy link

commented Apr 16, 2018

Thanks for this! 😄

@bwangelme

This comment has been minimized.

Copy link

commented May 30, 2018

It helps me, thanks!

@amfische

This comment has been minimized.

Copy link

commented Jun 19, 2018

Thank you man, much appreciated!

@eonist

This comment has been minimized.

Copy link

commented Sep 6, 2018

Where is the global gitignore file in macOS? ~/.config/git/ignore doesn't exist

@hbroer

This comment has been minimized.

Copy link

commented Oct 2, 2018

you set it to where ever you want it. If you set it with git config --global core.excludesfile ~/.gitignore you have to create it there: ~/.gitignore ;)

@nullcookies

This comment has been minimized.

Copy link

commented Oct 9, 2018

Thank you

@latch2112

This comment has been minimized.

Copy link

commented Mar 5, 2019

thanks

@koopmanj

This comment has been minimized.

Copy link

commented May 1, 2019

thx, for users with blanks in their profilename:
pwsh> git config --global core.excludesfile $env:USERPROFILE\.gitignore , quite obvious but for the most lazy folks

@fluffypomeranian

This comment has been minimized.

Copy link

commented May 28, 2019

thank you!

@tomholford

This comment has been minimized.

Copy link

commented Jun 26, 2019

Thank you, added this to my dotfiles:

https://github.com/tomholford/dotfiles

@OGProgrammer

This comment has been minimized.

Copy link

commented Sep 5, 2019

Had to edit vim ~/.gitignore as the command did not create the file on my mac.

@dioni21

This comment has been minimized.

Copy link

commented Sep 6, 2019

Nice hint, but please, suggest a differente name, like .gitgnore_global as shown at https://help.github.com/en/articles/ignoring-files

Many people use git at their home, for dotfiles, et al.

@erikyuzwa

This comment has been minimized.

Copy link

commented Sep 24, 2019

until last week, ~/.config/git/ignore was the way to go, but now I had to move to ~/.gitignore - OSX 10.14.6 with git 2.23.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.