当我有多个帐户时,将私有 Github 存储库克隆为协作者

Cloning a private Github repo as a collaborator when I have multiple accounts

我有 2 个 GitHub 个帐户:

帐户 1

账户2

在 account2 中,我被添加为某个 repo 的合作者:

account_notmine/repo_xyz

我已经为第二个帐户创建并添加了一个新的 ssh 密钥,并将其添加到 github。

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

Host github-new
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_new

现在,如果我尝试使用我的 account2 个人存储库之一,它工作正常。但是当我尝试克隆我作为合作者的 repo 时,它不起作用。

基本上,我所做的就是尝试执行这个命令:

git clone --bare git@github-new:account_notmine/repo_xyz.git

它给我的错误是:

Cloning into bare repository 'repo_xyz.git'...
Warning: Permanently added 'github.com,xxx.xxx.xxx.xxx' (RSA) to the list of known hosts.
ERROR: Repository not found.
fatal: Could not read from remote repository.

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

我做错了什么?

我过去也遇到过这个问题,我试图解决:

ERROR: Repository not found.
fatal: The remote end hung up unexpectedly

我听说发生这种情况的最常见原因是存储库名称中的拼写错误(区分大小写),存储库是否真的存在?也可能是查看存储库的权限不正确,或者在极少数情况下,存储库的 SSH 访问设置不正确。

我在这里找到了答案GitHub: ERROR: Repository not found. fatal: The remote end hung up unexpectedly (different from similar posts apparently)

希望对您有所帮助..:)

已解决:只需通过 SSH (ssh -T git@github-new) 调用我的 github 第二个帐户,我发现它回答了我:

Hi **account1**! You've successfully authenticated, but GitHub does not
# provide shell access.

然后我编辑了我的 ssh 配置文件,添加了 IdentitiesOnly yes 语句:

Host github.com
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa
  IdentitiesOnly yes

Host github-smartstay
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa_new
  IdentitiesOnly yes

嗯,成功了。