Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git uses the wrong identity (.ssh/config file not read ?)

Tags:

git

ssh-keys

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

like image 855
ValLeNain Avatar asked Mar 21 '20 10:03

ValLeNain


People also ask

How do I edit Gitconfig?

How to do a git config global edit? The global git config is simply a text file, so it can be edited with whatever text editor you choose. Open, edit global git config, save and close, and the changes will take effect the next time you issue a git command. It's that easy.

What is a .gitconfig file?

The . git/config file in each repository is used to store the configuration for that repository, and $HOME/. gitconfig is used to store a per-user configuration as fallback values for the . git/config file. The file /etc/gitconfig can be used to store a system-wide default configuration.

How do I create a Github key?

Login to github.com and bring up your account settings by clicking the tools icon. Select SSH Keys from the side menu, then click the Add SSH key button. Name your key something whatever you like, and paste the contents of your clipboard into the Key text box. Finally, hit Add key to save.


1 Answers

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
like image 79
jthill Avatar answered Oct 15 '22 21:10

jthill