6

I use gitlab.com for my company work, and github.com for my personal work. I've read lots of threads, lots of topics about identity problem and yet, I'm still not able to understand why it's not working from me.

I have a ~/.ssh/config file as follow

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/perso_id_rsa

Host gitlab
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_rsa

And a master ~/.gitconfig

[user]
    email = my_company_address
    name = my_company_name

[includeIf "gitdir:~/Workspace/perso"]
    path = ~/Workspace/perso/.gitconfig

And a ~/Workspace/perso/.gitconfig

[user]
    email = my_perso_email
    name = my_pseudo

When I'm making commits from my perso project in ~/Workspace/perso/my_perso_project, the commit author is my company address (the commit is pushed to github without problem).

Can somebody help ?

Thanks

ValLeNain
  • 2,232
  • 1
  • 18
  • 37
  • `.ssh` stuff is totally irrelevant to making new commits. `user.name` etc are totally irrelevant to doing ssh push/fetch operations. The `includeIf` directive requires a modern Git; what Git version are you using? – torek Mar 21 '20 at 10:36
  • I'm using git 2.17.1 – ValLeNain Mar 21 '20 at 10:47

2 Answers2

4

Your includeif is wrong. gitdir:~/Workspace/perso is not the .git dir, and doesn't have the search flag. See the git config docs for includeif,

If the pattern ends with /, ** will be automatically added. For example, the pattern foo/ becomes foo/**. In other words, it matches "foo" and everything inside, recursively.

Either name the specific git dir you're checking for or tell Git you mean any git dir in that entire subtree:

[includeIf "gitdir:~/Workspace/perso/.git"]
        path = ~/Workspace/perso/.gitconfig

or

[includeIf "gitdir:~/Workspace/perso/**"]
        path = ~/Workspace/perso/.gitconfig

or

[includeIf "gitdir:~/Workspace/perso/"]
        path = ~/Workspace/perso/.gitconfig
jthill
  • 55,082
  • 5
  • 77
  • 137
0

IncludeIf is indeed supported with Git 2.17.1 (it was introduced in 2.13)

As commented, ~/.ssh/config is only used for authentication, not authorship.

I would go to ~/Workspace/perso/my_perso_projec and do:

git config --list --show-origin

That way, you know which file will set the user.email.
The last displayed overrides the others.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250