【问题标题】:git config how use 2 username on same servergit config 如何在同一台服务器上使用 2 个用户名
【发布时间】:2018-07-19 09:38:54
【问题描述】:

我想在同一服务器 gitlab.com 上使用 2 个不同的用户名 这是我的实际配置文件:

Host gitlab.com
    HostName gitlab.com
    User username1
    IdentityFile ~/.ssh/id_rsa.username1
    IdentitiesOnly yes


Host gitlab.com
    HostName gitlab.com
    User username2
    IdentityFile ~/.ssh/id_rsa.username2
    IdentitiesOnly yes

如果我在第一个帐户中推送代码,工作 如果我尝试在第二个帐户中推送代码不起作用(因为使用第一个帐户的密钥) 仅适用于配置文件中的第一个职位帐户。

我如何在没有这个问题的情况下使用这两个帐户?

【问题讨论】:

标签: git github gitlab


【解决方案1】:

您必须更改 Host 以使其具有唯一性:

Host username1.gitlab.com
    HostName gitlab.com
    User username1
    IdentityFile ~/.ssh/id_rsa.username1
    IdentitiesOnly yes


Host username2.gitlab.com
    HostName gitlab.com
    User username2
    IdentityFile ~/.ssh/id_rsa.username2
    IdentitiesOnly yes

然后更改本地 git 存储库中的主机名:

user1/project>git remote -v 
origin git@gitlab.com/... (fetch)
origin git@gitlab.com/... (push)

user1/project>git remote remove origin
user1/project>git remote add origin git@username1.gitlab.com/...

当然也可以使用项目别名而不是用户名...

【讨论】:

  • 我如何使用 ssh 链接做到这一点? git@gitlab.com:usename/video-app.git 因为这样不起作用 git@username.gitlab.com:usename/video-app.git
  • @BelloDaniel “不工作”是什么意思?您是否在 .ssh/config 和存储库 URI(如 username**1**.gitlab.com)中使用了相同的 Host
猜你喜欢
  • 2019-05-25
  • 2016-01-02
  • 2023-03-18
  • 1970-01-01
  • 2015-09-06
  • 2018-05-24
  • 2013-09-21
  • 2016-01-29
  • 2011-07-09
相关资源
最近更新 更多