Here is yet another reason why it would not work: If ~
is a link (and you use it in the condition). This is because when git computes the gitdir of a repo git rev-parse --git-dir
, it gives the "realpath" of that directory with links resolved. If you have
[includeIf "gitdir:/a/link/c"]
and link -> target
, even if the repo is in /a/link/c/d/repo
, it won't go inside that section because git rev-parse --git-dir
will give a/target/c/d/repo
and that won't match a/link/c
.
Example context
For example at work, the true location of my home dir is say
/storage/${my_department$}/${my_username}
for organizational purposes. We also have a flat directory containing links to the homes of every user.
/home/${my_username} -> /storage/${my_department$}/${my_username}
and in the entry in the passwd file is the link /home/${my_username}
so my HOME environment variable gets set to that, and so ~
gets expanded to that as well.
I have
~/Repos/group_A/repo_{a1,a2,a3}
~/Repos/group_B/repo_{b1,b2,b3}
I had
[includeIf "gitdir:~/Repos/group_A"]
path = ~/Repos/group_A/gitconfig_A
[IncludeIf "gitdir:~/Repos/group_B"]
path = ~/Repos/group_B/gitconfig_B
which didn't work
Explanation
The above includeIf
s did not work for e.g. ~/Repos/group_A/repo_a1
because its git dir was /storage/${my_department}/${my_username}/Repos/group_A/repo_a1
which did not match ~/Repos/group_A
(since tilde expansion gives /home/${my_username}/group_A
.
The gitdir
does not start with ~/Repos/group_A
Solution
To solve this I'm refraining from using ~
and hardcoding the path with links resolved in the condition.
[includeIf "gitdir:/storage/${my_department}/${my_username}/Repos/group_A"]
path = ~/Repos/group_A/gitconfig_A
[IncludeIf "gitdir:/storage/${my_department}/${my_username}/Repos/group_B"]
path = ~/Repos/group_B/gitconfig_B
Note that I can still use ~
for the path =
part because the problem only arises from the string comparison between a path with links expanded and one with links unexpanded.
Version controlled .gitconfig
shared on different systems
This is kind of annoying since I version my .gitconfig
and use it on multiple systems so hardcoded paths are not fun.
So what I did was to divide my .gitconfig
in two, one that is versioned and one that is not
# .gitconfig (versioned)
[user]
name = "Philippe Carphin"
#...
[include]
path = ~/.gitconfig.specific
With the specific part all the way at the end so that the system specific stuff overrides the less specific stuff.
~/Business/
a repository (working tree)? If not hint:includeIf
works only in repositories under~/Business/
but not in a non-repo directory. – Paratyphoid