5

I've recently upgraded to git version 2.33.1.windows.1
and includeif does not seem to be working.
Can anyone else confirm? I can't remember what my previous git version was.

My config is as follows:

.gitconfig

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir:E:/work/**"]
  path = ~/.gitconfig_work

.gitconfig_work

[user]
    name = name.surname
    email = name.surname@work.com

The reason I upgraded was that the includeif was not taking effect recursively
on directories nested more than one directory below E:/work/

Since the upgrade it doesn't seem to be taking effect at all.

>git config -l --show-origin

Only shows entries from:

  • C:/Program Files/Git/etc/gitconfig
  • C:/Users/crowne/.gitconfig

I don't see any entries from:

  • C:/Users/crowne/.gitconfig_work
crowne
  • 8,456
  • 3
  • 35
  • 50
  • 1
    Try `[includeIf "gitdir/i:E:/work"]` (case-insensitive, no `**`). – phd Nov 16 '21 at 12:59
  • I tried, but its still not working – crowne Nov 17 '21 at 12:53
  • This is no longer a problem for me, I'm currently on git version 2.34.1.windows.1 however I'm also on a new computer and my work include path is now [includeIf "gitdir/i:**/work/**"] path = ~/.gitconfig_work – crowne Feb 22 '22 at 07:49

2 Answers2

7

I have tried git v2.35.1 and the magic was for me, to drop the ** in the end and keep the trailing slash / alone. I added also the /i option to ignore be case-insensitive.

.gitconfig, which worked for me

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir/i:E:/work/"]
  path = ~/.gitconfig_work

not working a)

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir/i:E:/work/**"]
  path = ~/.gitconfig_work

not working b)

[user]
  name = crowne
  email = crowne@fakemail.com
[includeIf "gitdir/i:E:/work"]
  path = ~/.gitconfig_work
KargWare
  • 1,746
  • 3
  • 22
  • 35
  • 2
    similar issue under ubuntu, after switched from Bionic (git v2.17) to Focal (git v2.25.1), I had `[includeIf "gitdir:~/workspace/*"]` and it worked under old version. Now I remove * : `[includeIf "gitdir:~/workspace/"]` equivalent to _/home/myusername/workspace/**_ and it works fine, https://stackoverflow.com/a/54125961/6614155 – bcag2 May 27 '22 at 12:21
  • The flat `/i` is important, because of the drive letter `C:` or `c:`... who knows what git thinks is the truth... – jeromerg Mar 14 '23 at 14:32
  • if you test with `git config --get user.email` make sure you are actually in a git repo inside the folder, otherwise it will return the default value – Guillermo Ruffino Jun 15 '23 at 17:47
0

I managed to get it working for me on windows by using the following:

.gitconfig

[includeIf "gitdir:**"]
path = C:/Users/myusername/.gitconfig-personal
[includeIf "gitdir:C:/Users/myusername/Desktop/work/**"]
path = C:/Users/myusername/.gitconfig-work

.gitconfig-personal and .gitconfig-work

[user]
name = My Name
email = myEmail@provider.com

So in this case it will always default to my normal email in .gitconfig-personal and in case I go to any of the repositories in the work folder it will use the .gitconfig-work details. (I haven't tried using the case incentivise option)