Why .gitconfig [includeIf] does not work?

Viewed 7030

System settings: MacOS Catalina 10.15.6

> git --version
git version 2.24.3 (Apple Git-128)

file: ~/.gitconfig :

[user]
    name = nickname
    email = nickname@gmail.com
[includeIf "gitdir:~/Business"]
    path = ~/.gitconfig-work

file: ~/.gitconfig-work :

[user]
    name = First Last
    email = fl@work.com

Output when trying to check the configuration on terminal:

(base) MBP-Name:~ myname$ cd ~/Business/
(base) MBP-Name:Business myname$ git config --get user.name
nickname

I have tried both relative ~ and absolute / paths either for gitdir and path in the config file. On each change I am restarting the bash. Also, I have read several other stackoverflow questions with no success. Some of them where suggesting adding the i option for case insensitivity but it didn't fix the problem.

Any ideas ?

2 Answers

I myself also had issues with my .gitconfig. I read the docs a few times, searched Stackoverflow and some blogposts. I though I have tried every possible solution for it: relative paths, trailing slashes, different quotes, et cetera. Non of the solutions I tried actually worked.

I got to the point I just tried to include a file using [include], but with no success either.

After a few hours of trying and searching for answers, I came across a post that mentioned a .gitconfig to be included could also be a .txt file. I changed the files from .gitconfig-{company} to gitconfig-{company}.txt and renamed the paths in the global .gitconfig, and everything worked instantly!

I hope this works for you, and future googlers.

Related