![](/img/trans.png)
[英]How to push to multiple Git repositories using multiple accounts on the same machine?
[英]How can I push to multiple GitHub accounts from my PC using git? (different repositories)
是否可以在多个帐户中推送到不同的远程存储库? 我在 GitHub 中有 2 个帐户,并且每个帐户都有 1 个存储库克隆到我的 PC 中。 我在两个 repos 中都提交了,我想将它们分别推送到各自的远程。 对于第一个 repo,当我将它推送到远程时,它要求输入用户名和密码。 但是后来当我尝试将第二个 repo 推送到它的远程 repo 时,它说permission denied
,它甚至不要求任何授权并给我这个错误
remote: Permission to anasbasheer/anasbasheer.github.io.git denied to an4s911.
fatal: unable to access 'https://github.com/anasbasheer/anasbasheer.github.io.git/': The requested URL returned error: 403
在此之后,我尝试使用 SSH 键,但没有任何区别。
我该如何解决这个问题?
解决了!
我为两个帐户制作了 2 个不同的 ssh 密钥,现在每次我想推送到特定帐户时,我都必须不断更改 ssh 密钥。 (至少有总比没有好)
这些是我所做的步骤:
1.我做了一个ssh钥匙。
$ssh-keygen -t rsa -C 'name@email.com'
这里我在提示时给了
id_rsa
作为文件名
$eval $(ssh-agent -s)
$ssh-add ~/.ssh/id_rsa
2.我复制了密钥并在我的主 GitHub 帐户中添加了新的 SSH 密钥
复制密钥
$clip < ~/.ssh/id_rsa.pub
在 GitHub 中添加新的 SSH 密钥
Go 到 GitHub > 右上角的下拉菜单 > 设置 > SSH 和 GPG 密钥 > 新的 Z7650353E6C78 密钥 >785AC 在那里粘贴
3.我用相同的步骤制作了另一个密钥,但文件名为id_rsa_2
现在,在使用id_rsa
的前 2 个步骤中,它应该被替换为id_rsa_2
然后我将此密钥添加到我的第二个帐户。
4.现在我使用 SSH 链接将两个存储库克隆到我的计算机
$git clone git@github.com:username/repo-name.git
5.就是这样,现在每次我想推送到其中一个帐户时,我都必须更改 ssh 密钥
更改 SSH 密钥
$ssh-add ~/.ssh/your-key
就我而言, your-key
将是id_rsa
或id_rsa_2
希望这对其他人有帮助。
首先,您需要将远程存储库添加到本地存储库。
git remote add origin https://github.com/user/repo.git
git remote add origin2 https://github.com/user/repo2.git
将origin
和origin2
更改为您想要的任何内容。
然后只需使用您要推送分支的远程名称:
git push <REMOTENAME> <BRANCHNAME>
git push origin2 master
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.