Are .gitignore
files from directories above the repository's or from home directory (~/.gitignore
) loaded in any versions of Git?
~/.gitignore
is mentioned by some advisory web postings despite not working in the version of Git on my system, and my system manual is unclear about how far up Git will walk looking for a .gitignore
, although only mentions $XDG_CONFIG_HOME/git/ignore
as a home directory global gitignore file location.
My problem stems from, to manage my home directory dotfiles i have presently chosen to use Git with a custom GIT_DIR
environment variable setting, which does fine with not having Git default to that repository in any subdirectories of my ~
.
But, as .gitignore
is hardcoded and can't be selected by an environment variable (which i would like to be like "${GIT_DIR%/}ignore"
), being afraid that on some of my systems ~/.gitignore
could end up applying either globally or in repositories in the subdirectories of ~
, i resorted to adding the below snippet to my ${GIT_DIR}/info/exclude
and then staging the ${GIT_DIR}/info/exclude
file into the repository, keeping all my gitignore entries that are to apply to my dotfiles management repository in there (and in .gitignore
files in dotfiles-only subdirectories). What i don't like about it is that it's pretty dirty and it might cause minor problems sometimes.
The snippet mentioned above, with .gd
being my $GIT_DIR
:
/.gd/**
!/.gd/info/
!/.gd/info/exclude
The global ignore path is configurable (through the 'core.excludesFile' option), and until git version 1.7.12 it actually didn't have $XDG_CONFIG_HOME/git/ignore
as the default value – the option used to be blank by default.
Therefore many people used to manually configure git to load ~/.gitignore
as the global ignore file. Most likely everyone preferred this path due to its proximity to the ~/.gitconfig file (which is where global settings were kept pre-1.7.12).
However, this only happens to use the same filename, but otherwise is completely unrelated to the per-repository .gitignore
search which always stops at worktree root.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments