'Git "includeIf" directive not working (Ubuntu) [duplicate]

I want to specify separate gitconfig settings for projects inside a "work" directory, using the "includeIf" directive.

I have ~/.gitconfig:

[user]
        name = Dustin Michels
        email = [email protected]

(...)

[includeIf "gitdir:~/GitRepos/Work/"]
        path = ~/.gitconfig-work

And ~/.gitconfig-work:

[user]
        name = Dustin Michels
        email = [email protected]

When I naviagte into the ~/GitRepos/Work/ directory, or a Git project within, I still see the old settings.

$ git config user.email

[email protected]

Or

$ git config --list

user.name=Dustin Michels
[email protected]
(...)
includeif.gitdir:~/GitRepos/Other/.path=/.gitconfig-work

It seems that the directive is not being recognized? Or something else is wrong? I am using Ubuntu and git version 2.25.1.

git


Solution 1:[1]

According to git-config documentation it might be that the path has some letters capitalized / lower case that are being misspelled. Also, the ~ character points to the value of your HOME variable, that if it is not /home might be causing the issue.

If so, replace with:

[includeIf "gitdir/i:/home/GitRepos/Work/"]

Solution 2:[2]

if you copied from a website, make sure to check and retype the quotes

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Lawrence