Global Git ignore Global Git ignore git git

Global Git ignore


You need to set up your global core.excludesfile configuration file to point to this global ignore file.

e.g.

*nix or Windows git bash:

git config --global core.excludesFile '~/.gitignore'

Windows cmd:

git config --global core.excludesFile "%USERPROFILE%\.gitignore"

Windows PowerShell:

git config --global core.excludesFile "$Env:USERPROFILE\.gitignore"

For Windows it set to the location C:\Users\{myusername}\.gitignore. You can verify that the config value is correct by doing:

git config --global core.excludesFile

The result should be the expanded path to your user profile's .gitignore. Ensure that the value does not contain the unexpanded %USERPROFILE% string.

Important: The above commands will only set the location of the ignore file that git will use. The file has to still be manually created in that location and populated with the ignore list. (from muruge's comment)

You can read about the command at https://help.github.com/articles/ignoring-files/#create-a-global-gitignore


Before reconfiguring the global excludes file, you might want to check what it's currently configured to, using this command:

git config --get core.excludesfile

In my case, when I ran it I saw my global excludes file was configured to

~/.gitignore_global
and there were already a couple things listed there. So in the case of the given question, it might make sense to first check for an existing excludes file, and add the new file mask to it.


Although other answers are correct they are setting the global config value whereas there is a default git location for the global git ignore file:

*nix:

~/.config/git/ignore

Windows:

%USERPROFILE%\git\ignore

You may need to create git directory and ignore file but then you can put your global ignores into that file and that's it!

Source

Which file to place a pattern in depends on how the pattern is meant to be used.

  • Patterns which a user wants Git to ignore in all situations (e.g., backup or temporary files generated by the user’s editor of choice) generally go into a file specified by core.excludesFile in the user’s ~/.gitconfig. Its default value is $XDG_CONFIG_HOME/git/ignore. If $XDG_CONFIG_HOME is either not set or empty, $HOME/.config/git/ignore is used instead.