gpt4 book ai didi

git - 推送到多个 github 帐户

转载 作者:行者123 更新时间:2023-12-02 14:20:25 25 4
gpt4 key购买 nike

我目前需要推送到多个 github 帐户的情况。
为简单起见,让我们考虑两个帐户。

https://github.com/user1/repositoryName
https://github.com/user2/repositoryName

我曾经使用 user1,这是我的个人帐户。
User2 是我的工作帐户。

现在,当我 git push 到我的工作帐户时:
remote: Permission to user2/repositoryName.git denied to user1.
fatal: unable to access 'https://github.com/nitte93/reactogram.git/': The requested URL returned error: 403

经过一番浏览,我知道我需要为每个帐户设置一个单独的 SSH key 。

所以我做了。

对于个人
cd .ssh 
ssh-keygen -t rsa -b 4096 -C "user1@example.com"
//gave it a name of personal
chmod 400 ~/.ssh/personal
ssh-add ~/.ssh/personal

Added it to github>settings>ssh.

工作用
cd .ssh 
ssh-keygen -t rsa -b 4096 -C "user1@work.com"
//gave it a name of work
chmod 400 ~/.ssh/work
ssh-add ~/.ssh/work

Added it to github>settings>ssh.


ls .ssh
Had both the files.
Namely: peronal personal.pub work work.pub defaultones

接下来我做了:
   vi config

将其更新为
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/personal

Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/personal

已修改:ssh -T git@github.com
收到一条消息:
Hi user1! You've successfully authenticated, but GitHub does not
provide shell access.

问题是我的工作链接的形式是: https://github.com/work并不是
工作.github.com
但只有 user2(work) 可以访问它。 User2(个人)没有。

接下来,当我尝试推送到我的工作仓库时。我不断收到同样的错误。
remote: Permission to user1/repositoryName.git denied to user2.
fatal: unable to access 'https://github.com/nitte93/reactogram.git/': The requested

我知道还有其他几个问题涉及同一问题。但我相信我正确地跟随了他们。我不确定我是否缺少任何步骤。
如果我缺少任何步骤,请指导我。
我希望能够推送到两个存储库。

最佳答案

如果你使用 SSH 作为 GitHub 的远程,那么你不应该使用使用 https:// 的远程 URL。 .您的 Remote 应如下所示:

git@github.com:user1/repository.git

关于git - 推送到多个 github 帐户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38055341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com