git - 使用辅助键推送到受邀回购
问题描述
我的电脑上有两个 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.
我已经检查了两次和三次。回购地址是正确的。
请帮忙!
提前致谢!
解决方案
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
推荐阅读
- c++ - 基类捕获不捕获异常,即使它出现在派生类捕获之前
- javascript - 在 Chessboard.js 中检查 Checkmate
- python - Python链表删除重复项
- javascript - 无法从 shopify 输入字段中获取 val()
- objective-c - 为什么我的 JSONModel 类被视为 NSDictionary?
- nginx - 我可以在 NGINX 中执行 GeoIP 阻止而无需为 NGINX Plus 付费吗?
- c++ - 不一致的字符串/wchar 内容取决于代码的位置?
- node.js - nodejs 是否支持在一个路由器中更新多个集合?
- python - 是否可以在 sympy 中定义抽象复合符号?
- razor - 如果文本框有文本,则标记复选框