【问题标题】:Configuring git client for multiple git servers为多个 git 服务器配置 git 客户端
【发布时间】:2023-03-19 16:03:02
【问题描述】:

我的工作需要使用不同的凭据连接到多个 Git 服务器。我有我的个人存储库mypersonal@github.com、我的办公室工作存储库myoffice@bitbucket.com 和我的客户工作存储库mycustomer@customer.com

我需要使用不同的凭据(可以访问各自的存储库)定期访问这些不同的存储库并将代码推送到这些不同的存储库

如何配置我的 git 客户端(我在 Windows 上使用 git shell - powershell)以在每次连接到远程存储库时提示我输入用户 ID 和密码?理想情况下,我宁愿不必管理证书。

注意:我已经设置了全局变量。现在无法取消设置。

如果 git bash 比 git shell 更可取,我也对此持开放态度。我只是觉得 git shell 更容易处理,因为我习惯了 Windows 环境。

【问题讨论】:

标签: git github git-bash git-shell


【解决方案1】:

您可以从.ssh/config 中受益,以区分您的 git 帐户而不是 ssh。注意域的不同和键的指向:

#account1
Host github.com-account-one
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_account_one

#account2
Host github.com-account-two
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_account_two

例如要使用account1,请确保在本地存储库中从github.com-account-one 设置原始url 或clone,正确的登录信息将如下所示:

 git clone ssh://git@github.com-account-one:/MyRepo/myrepo.git 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2015-11-28
    • 2021-07-31
    • 1970-01-01
    • 2015-08-20
    • 2017-05-27
    相关资源
    最近更新 更多