首页 > 解决方案 > 使用辅助键推送到受邀回购

问题描述

我的电脑上有两个 github 帐户:一个用于工作,一个用于我的个人帐户。(我在 Mac 上)我的 .ssh 配置文件:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com-personalAccount
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_personal

这工作正常。我将 ssh 密钥添加到我的 github 帐户。我可以很好地推送到我的个人仓库,也可以推送到工作仓库。

现在,我被邀请作为第三个 repo 的合作者,我接受了邀请。我想我可以使用我的个人 ssh 密钥:

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_rsa

Host github.com-personalAccount
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_personal

Host github.com-otherUserAccount
  HostName github.com
  User git
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_personal

然后,在回购中:

git remote add origin git@github.com:otherUserAccount/redacted.git
git add .
git commit -m "Initial commit"
git push -u origin master

但它不起作用。我收到此错误:

ERROR: Repository not found.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

我已经检查了两次和三次。回购地址是正确的。

请帮忙!

提前致谢!

标签: gitgithubssh

解决方案


Git 不会传递给 SSH 存储库名称,它只会传递user@hostname. 因此,要让 SSH 使用正确的密钥,Git 必须传递从远程 URL 获取的正确主机名。您.ssh/config的远程 URL 必须是(就 Git 命令而言):

git remote set-url origin git@github.com-personalAccount:personalAccount/personalRepo.git

git remote set-url origin git@github.com-otherUserAccount:otherUserAccount/otherRepo.git

推荐阅读