github - Conflict between two git accounts on same system - Stack Overflow

admin2025-04-17  2

I've added two ssh config in ~/.ssh/config:

Host account1
  User git
  Hostname github
  PreferredAuthentications publickey
  IdentityFile /home/USER/.ssh/account2_ssh


Host account2
  User git
  Hostname github
  PreferredAuthentications publickey
  IdentityFile /home/USER/.ssh/account1_ssh

What I am understanding is that with git clone git@account1:Account1/app.git the account1's ssh key will be used for authentication. Hence, account1 will be the author of that commit, which is where i am facing the when that account2 is becoming the author of that commit instead of account1.

I am expecting the author of that commit to be the one with whose ssh config Host setting the repo was initialized. I am also confused about who owns repo when we initialize the git locally using git init.

First time asking a question here, Thank you!

I've added two ssh config in ~/.ssh/config:

Host account1
  User git
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile /home/USER/.ssh/account2_ssh


Host account2
  User git
  Hostname github.com
  PreferredAuthentications publickey
  IdentityFile /home/USER/.ssh/account1_ssh

What I am understanding is that with git clone git@account1:Account1/app.git the account1's ssh key will be used for authentication. Hence, account1 will be the author of that commit, which is where i am facing the when that account2 is becoming the author of that commit instead of account1.

I am expecting the author of that commit to be the one with whose ssh config Host setting the repo was initialized. I am also confused about who owns repo when we initialize the git locally using git init.

First time asking a question here, Thank you!

Share Improve this question asked Feb 1 at 10:10 KaranKaran 133 bronze badges 1
  • 2 Logins/passwords, access tokens, SSH keypairs are authorization credentials. They're used during remote operations (pull/push/etc) and never used during commit creation. user.name/user.email from config are commit identification data used during commit creation. – phd Commented Feb 1 at 11:03
Add a comment  | 

1 Answer 1

Reset to default 4

There is no relationship between the ssh key/authentication and the commit author.

The author is set by the git setting git config user.name "John Doe"

You can use differnet settings for different project or use automatic config settings, described here Is it possible to have different Git configuration for different projects?

转载请注明原文地址:http://anycun.com/QandA/1744832536a88243.html