【问题标题】:Access different github accounts from different git local config从不同的 git 本地配置访问不同的 github 帐户
【发布时间】:2020-10-27 16:58:48
【问题描述】:

这里有两个不同的用户在 github.com

  • "user-one" (one@mail.com)
  • “用户二”(two@mail.com)

每个用户都有自己的存储库,其中包含不同的项目帐户

现在我的电脑上有我:我想将本地配置设置为

  • "folder-one" 定位 repo-one 以上传项目更改,因此:
    • git config --local user.name "user-one"
    • git config --local user.email one@mail.com
  • “folder-two”针对 repo-2 上传项目更改,所以:
    • git config --local user.name "user-two"
    • git config --local user.email two@mail.com

当我推送到“repo-one”时,GitHub 会在我的计算机中安装一个凭据(如 git:https://github.com),让我只能将更改上传到该 repo。

问题

每次我推送到不同的存储库时,我都可以解决删除该凭据的问题,但是有更好的方法吗?有什么方法可以保存每个新用户数据而不是拒绝我的访问?

解决方案建议

如何让 GitHub 知道我将处理不同的帐户,这些帐户将向他们推送各自不同的存储库?

【问题讨论】:

    标签: github github-actions git


    【解决方案1】:

    使用两个不同的帐户推送:

    一种方法可能是:在本地 .ssh/config 中定义两个 Host 部分,它们都将针对 github,但使用不同的键:

    Host ghuser1
        Hostname github.com
        User git
        IdentityFile path/to/user1/publickey
    
    Host ghuser2
        ...
    

    然后您可以将两个遥控器设置为ghuser1:[user]/[repo]ghuser2:[user]/[repo]

    [编辑] 在媒体上挖掘出这个更详细的链接:Use multiple ssh-keys for different GitHub accounts
    来自另一个 SO 问题:Make git-submodule update from specific Host in config


    请注意,user.nameuser.email 用于在每次提交时写入提交作者。将这些值保留给您希望在历史记录中拥有的作者。

    【讨论】:

    • “Host + .ssh/config”就像我正在寻找的那样。我会深入研究的。
    猜你喜欢
    • 2013-06-04
    • 2022-12-11
    • 1970-01-01
    • 2019-07-10
    • 2023-03-15
    • 2017-05-12
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多