繁体   English   中英

如何使用别名访问远程存储库?

[英]How to access remote repositories using aliases?

由于我希望能够使用多个标识/键来push代码。 为此,我在~/.ssh/config定义了一些别名:

#github.com default
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_foo

#github.com-foo
Host github.com-foo
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_foo

#github.com-bar
Host github.com-bar
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_bar

...

要访问我的仓库,我使用别名,例如:

$ git remote add origin git@github.com-foo:MyOrganizationOrPersonalAccount/MyRepo.git
$ git remote -v
origin  git@github.com-foo:MyOrganizationOrPersonalAccount/MyRepo.git (fetch)
origin  git@github.com-foo:MyOrganizationOrPersonalAccount/MyRepo.git (push)

很长时间以来,它一直运行良好。 现在(可能是因为我重新安装了操作系统)它不再起作用了:

$ git fetch
Unable to open connection:
Host does not existfatal: Could not read from remote repository.

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

是什么可能导致此问题,以及如何使远程访问正常工作?

更新

为了确保运行我重新安装Git,我正在使用OpenSSH客户端。 现在可以了。 所以我想这个问题是由使用plink作为SSH客户端引起的,它没有考虑~/.ssh/config设置。

我前一段时间收到此错误,要解决此问题,我从列表中删除了远程

git remote remove MyRemote

然后再次添加它,如果使用ssh键,则使用HTTP链接

git remote add Http://URLToRepositoryHere

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM