简体   繁体   English

具有多个 SSH 密钥的多个 github 帐户导致多个贡献者

[英]Multiple github accounts with multiple SSH keys resulting in multiple contributors

I have 2 different Github accounts.我有 2 个不同的 Github 帐户。 And I've setup 2 different SSH keys.我已经设置了 2 个不同的 SSH 密钥。 Registered both keys on Github with the correct account and created a git config file that should use the right credentials for working with the remote repository (ie use my personal account for personal work and work account for remote work).使用正确的帐户在 Github 上注册了两个密钥,并创建了一个git config文件,该文件应该使用正确的凭据来处理远程存储库(即使用我的个人帐户进行个人工作和工作帐户进行远程工作)。 This is what my git config file looks like:这是我的 git 配置文件的样子:

Host personal.github.com
HostName github.com
User git
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_personal
IdentitiesOnly yes

Host work.github.com
HostName github.com
PreferredAuthentications publickey
User git
IdentityFile ~/.ssh/id_rsa_work
IdentitiesOnly yes

It works, I can clone and push projects.它有效,我可以克隆和推送项目。

The problem:问题:

Let's say i create a new remote repo in my work account.假设我在我的工作帐户中创建了一个新的远程存储库。 When I clone the project on my local machine I use: git clone git@work.github.com:[username]/my-plan.git当我在本地机器上克隆项目时,我使用: git clone git@work.github.com:[username]/my-plan.git

Then make some changes, commit them and push it back to the remote repo.然后进行一些更改,提交它们并将其推送回远程仓库。 It works, but instead of showing my work account credentials under "Contributors" it actually shows my personal account.它有效,但不是在“贡献者”下显示我的工作帐户凭据,它实际上显示了我的个人帐户。

If I run git remote -v I get:如果我运行git remote -v我得到:

origin  git@work.github.com:[username]/my-plan.git (fetch)
origin  git@work.github.com:[username]/my-plan.git (push)

I dont understand why is this happening when the associated SSH key is connected to my work account and not my personal account.我不明白为什么当关联的 SSH 密钥连接到我的工作帐户而不是我的个人帐户时会发生这种情况。 What I need to do to make sure that every time i push the project back, its from my work account and not personal one?我需要做些什么来确保每次我将项目推回时,它来自我的工作帐户而不是个人帐户?

I think the problem is not with your SSH keys, github differs user that "pushed" commit and one who "committed" changes.我认为问题不在于您的 SSH 密钥,github 将“推送”提交的用户与“提交”更改的用户不同。

You can use your browser to navigate to:您可以使用浏览器导航到:

https://api.github.com/repos/[username]/[repo]/commits

Each commit will have每次提交都会有

  "author": {
    "name": "<author1>",
    "email": "<email1>",
    "date": "2019-09-17T12:56:43Z"
  },
  "committer": {
    "name": "<author2>",
    "email": "<email2>",
    "date": "2019-09-17T12:56:43Z"
  },

If emails are different - that's the problem and you should configure your git for current project locally ( git config user.email "<your email for this repo>" ).如果电子邮件不同 - 这就是问题所在,您应该在本地为当前项目配置 git( git config user.email "<your email for this repo>" )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM