2

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 = my@personal-email.com

(...)

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

And ~/.gitconfig-work:

[user]
        name = Dustin Michels
        email = my@work-email.com

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

$ git config user.email

me@personal-email.com

Or

$ git config --list

user.name=Dustin Michels
user.email=me@personal-email.com
(...)
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.

Dustin Michels
  • 2,951
  • 2
  • 19
  • 31
  • Works for me. Debian 10, `git` 2.20. Works only inside a working tree under `~/GitRepos/Other/`, not in the root of `~/GitRepos/Other/`. Double check git version, paths, syntax. Includes should go after the settings they override, most probably at the very end of `~/.gitconfig`. – phd May 28 '20 at 11:38
  • I had an unnecessary asterisk at the end of the `includeif` condition, but it doesn't seem to be your case. – StaNov Jul 22 '20 at 14:34
  • @phd it does work inside working tree but there are duplicate usernames in git config --list which one will be used. Also doing ssh -T github.com-work prints the personal username – kailash yogeshwar Aug 28 '20 at 11:27
  • @kailashyogeshwar "*there are duplicate usernames in git config --list*" Not for me. I use `includeIf` to replace `user.email` — works perfectly. "*Also doing ssh -T github.com-work prints the personal username*" That's a completely different question, related to `ssh` config, not related to `includeIf`. – phd Aug 28 '20 at 11:44
  • Try `git config --list --show-origin` and see what it says for user.name and user.email – Lasse V. Karlsen Dec 08 '21 at 12:17
  • did you get it sorted? I see the same. – webduvet Jul 05 '22 at 20:27

2 Answers2

1

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

Lawrence
  • 21
  • 1
0

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/"]
Jonatan Kruszewski
  • 1,027
  • 3
  • 23