DEV Community


Discussion on: I just asked: Are .gitignore files from directories above the repository's or from home directory loaded in any versions of Git?

_marekj profile image
Marek Jay • Edited

git looks for a .gitignore file in your current local clone (the dir with .git dir) but you can DRY your gitignore for all your projects by maintaining a global gitignore in a ~/.gitignore for example and you tell git where it is with a core.excludesfile section declaration.


git config --global core.excludesfile

.. should tell you if you have it(if any) If not, you can declare the file where your global user gitignore file is with:

git config --global core.excludesfile "$HOME"/.gitignore

Examine your global git config with git config --global --list or brute force just open your $HOME/.gitconfig file

Once you set up a global .gitignore excludesfile you will not need to keep pasting the same .gitingnore in each repo you work in, thus you have sensible defaults and DRY in play. All the best

mkf profile image
Michał Krzysztof Feiler Author

so ~/.gitignore as a custom filename to be mentioned in ~/.gitconfig under core.excludesfile is an alternative to ~/.config/git/ignore, but can we say that we are sure no outdated version of Git ever had ~/.gitignore hardcoded, and no outdated version of Git walked further up than $GIT_WORK_TREE looking for .gitignore?

_marekj profile image
Marek Jay • Edited

git does not walk UP anywhere, if I can say that. It only acts on the current directory where .git lives; but it also uses the global file (user space, the global in this context means You, the user, not everyone on the machine) located at ~/.gitconfig, which governs how git behaves for You, the user (global may be confusing to people) in all the repos you work on that machine (repo, meaning a working dir with .git dir)

The declaration core.exludesfileasks you to point to a file that holds the global (to you) ignore patterns you want to apply to all REPOS you have in your workspace. (

Where the ignore file is located is irrelevant, but by some sensible default I would suggest ~/.gitingnore, yet it can be ~/gitlistaignorancja or ~/whatever-blabla-git ... - and no, git never hardcodes the ~/.gitignore name (only local .git/gitignore) . It does respect the GIT_DIR/.gitignore because it treats it as a WORKSPACE local ignore patterns (in addition to what's in global excludesfile)

Git does not walk up to any dirs up to find stuff (unlike NPM if you ever worked with it). It only looks at your local WORKING DIR (local gitconfig), the global (user space) declarations in ~/.gitignore and the system (indeed global to all users) file. Hope this makes sense.