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

@liukun liukun 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

@ElMatella ElMatella 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

@markwartman1 markwartman1 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

@randallb randallb commented Apr 16, 2018

Thanks for this! 😄

@bwangelme

This comment has been minimized.

Copy link

@bwangelme bwangelme commented May 30, 2018

It helps me, thanks!

@amfische

This comment has been minimized.

Copy link

@amfische amfische commented Jun 19, 2018

Thank you man, much appreciated!

@eonist

This comment has been minimized.

Copy link

@eonist eonist 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

@hbroer hbroer 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

@nullcookies nullcookies commented Oct 9, 2018

Thank you

@latch2112

This comment has been minimized.

Copy link

@latch2112 latch2112 commented Mar 5, 2019

thanks

@koopmanj

This comment has been minimized.

Copy link

@koopmanj koopmanj 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

@timxor

This comment has been minimized.

Copy link

@timxor timxor commented May 28, 2019

thank you!

@tomholford

This comment has been minimized.

Copy link

@tomholford tomholford commented Jun 26, 2019

Thank you, added this to my dotfiles:

https://github.com/tomholford/dotfiles

@OGProgrammer

This comment has been minimized.

Copy link

@OGProgrammer OGProgrammer 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

@dioni21 dioni21 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

@erikyuzwa erikyuzwa 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

@samuelwilliams

This comment has been minimized.

Copy link

@samuelwilliams samuelwilliams commented Dec 20, 2019

For adding the Windows global ignore, in some instances there should be quotes around the path, i.e. git config --global core.excludesfile "%USERPROFILE%\.gitignore" as %USERPROFILE% may contain spaces that git will not parse correctly.

Exempli Gratia: C:\Users\Joe Bloggs\.gitignore.

Git will not add the .gitignore path correctly without double quotes.

@BenjaminRqt

This comment has been minimized.

Copy link

@BenjaminRqt BenjaminRqt commented Jan 9, 2020

@sF0rman

This comment has been minimized.

Copy link

@sF0rman sF0rman commented Feb 18, 2020

had to name the file .gitignore_global for it to work for me (on windows 10)
https://stackoverflow.com/questions/7529266/git-global-ignore-not-working

@rpgdev

This comment has been minimized.

Copy link

@rpgdev rpgdev commented Apr 19, 2020

Naming this file .gitignore seems to be somewhat of a misnomer. On Linux at least, a .gitignore file and the core.excludesfile file seem to be interpreted differently by git. For example, this rule .dir/* would be completely ignored in a core.excludesfile but not in a .gitignore.

@lanyado

This comment has been minimized.

Copy link

@lanyado lanyado commented Jun 22, 2020

Thank you!

@skupjoe

This comment has been minimized.

Copy link

@skupjoe skupjoe commented Jun 24, 2020

One more thing to add,

Make sure you do this from a command prompt. Powershell will not expand the %USERPROFILE% and it will use this string literally.

@skupjoe

This comment has been minimized.

Copy link

@skupjoe skupjoe commented Jul 8, 2020

I found that using .gitgnore_global, for whatever reason, works more reliably with pattern matching. Not sure why!

git config --global core.excludesfile "%USERPROFILE%\.gitignore_global"
@rafaelkendrik

This comment has been minimized.

Copy link

@rafaelkendrik rafaelkendrik commented Sep 8, 2020

If the file that you want to ignore already exists in the repository, you can use update-index:

$ git update-index --assume-unchanged FILENAME
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.