ssh到两个单独的gitlab帐户

时间:2018-02-12 22:57:38

标签: git github ssh gitlab

我有两个单独的gitlab帐户,每个帐户都有一个唯一的SSH密钥,并使用不同的email创建。我如何push/pull通常(git push origin master / git pull origin master)来自两个帐户的回购?我是否必须同时配置〜/ .gitconfig和〜/ .ssh / config?

第一个gitlab帐户(username1,email1 @ gmail.com)

第二个gitlab帐户(username2,email2 @ gmail.com)

的〜/ .ssh /配置

 Host gitlab.com
    User username1
    IdentityFile ~/.ssh/id_rsa

    Host gitlab.com
    User username2
    IdentityFile ~/.ssh/id_rsa_

〜/的.gitconfig

[user]
name = Bob
email = email1@gmail.com
username = username1

问题是我只能使用此配置从一个仓库中提取而不是两者都是。怎么能让两者都有效?

1 个答案:

答案 0 :(得分:0)

你可以通过编辑你〜/ .ssh / config

来做到这一点

这里为每个帐户添加两个部分。就像这个例子。

#user1 account
Host gitlab.com-user1
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab-user1

#user2 account
Host gitlab.com-user2
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab-user2

然后你必须改变远程网址,如下所示。

使用帐户1 git@gitlab.com-user1:<yourProjectToClone>

使用帐户2 git@gitlab.com-user2:<yourProjectToClone>

希望这会有所帮助。

相关问题