DEV Community

loading...

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

Collapse
_marekj profile image
Marek Jay

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. (git-scm.com/docs/gitignore)

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.