git - Multiple github accounts with multiple SSH keys resulting in multiple contributors
问题描述
I have 2 different Github accounts. And I've setup 2 different SSH keys. 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). This is what my git config file looks like:
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
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:
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. 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?
解决方案
我认为问题不在于您的 SSH 密钥,github 与“推送”提交的用户和“提交”更改的用户不同。
您可以使用浏览器导航到:
https://api.github.com/repos/[username]/[repo]/commits
每个提交都会有
"author": {
"name": "<author1>",
"email": "<email1>",
"date": "2019-09-17T12:56:43Z"
},
"committer": {
"name": "<author2>",
"email": "<email2>",
"date": "2019-09-17T12:56:43Z"
},
如果电子邮件不同 - 这就是问题所在,您应该在本地为当前项目配置 git ( git config user.email "<your email for this repo>"
)。
推荐阅读
- business-process-management - 如何在 Workfusion RPA Express 中将变量值从一个机器人任务传输到另一个机器人任务?
- java - 与迭代器一起使用时,openCSV CSVReader getRecordsRead 方法返回错误计数
- maven - Mulesoft Munit Maven 构建失败
- linux - 如何在linux中添加打印语句来计算带有关键字的行数
- object - 如何找到没有循环的javascript对象的最后一个元素?
- c - 使用模数的 C 加法
- php - 使用 curl php 发送多个文件数据(要发送的文件数量不同)
- node.js - 客户端正在与 mosquitto 代理断开连接,并且不再连接到同一个代理
- java - 结果集在 Java 中不起作用
- php - 如何将多个数据添加到表中的多个字段中