git - 两个 github 帐户推送到同一个 repo

标签 git github

<分区>

所以这是一个非常具体的用例。如果有任何 GitHub 专家可以帮助我,那就太好了。

在我的 Linux 笔记本电脑中,我想使用两个不同的 GitHub 用户名推送到相同 GitHub 存储库。

我已经在我的本地机器上设置了两个 SSH key 。我已经能够配置它,直到能够在提交时在用户之间切换。这工作正常,我可以在提交时在两个配置的用户之间切换。

但是,每当我执行 git push 时,我永远无法切换用户,它总是使用我的第一个用户名。

推送到github时有没有办法切换或选择用户?

最佳答案

释义 this answer :

您可以在 ~/.ssh/config 中创建两个不同的主机名。
例如,如果您的配置如下所示:

Host github-as-alice
  HostName github.com
  User git
  IdentityFile /home/whoever/.ssh/id_ed25519.alice
  IdentitiesOnly yes

Host github-as-bob
  HostName github.com
  User git
  IdentityFile /home/whoever/.ssh/id_dsa.bob
  IdentitiesOnly yes

然后你只需使用 github-as-alicegithub-as-bob 而不是你 URL 中的主机名:

git clone github-as-alice:name/whatever.git
cd whatever
git remote add bob github-as-bob:name/whatever.git

注意:您还可以通过在 Host github.com 部分简单地提及它来为 github 设置一个“默认” key :

Host github.com
  User git
  IdentityFile /home/whoever/.ssh/id_ed25519.github

关于git - 两个 github 帐户推送到同一个 repo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64989473/

相关文章:

java - 为什么将 gradle java 应用程序部署到 heroku 失败?

android - Github 存储库 - LockFile 存在

git - 我应该提交 .gitignore 文件吗?

git - "Proper" pull git "production branch"到生产服务器的方法

Git Merge Conflict修改/删除

git - 无法在 Gerrit 中 merge

python - Tensorflow 服务应该克隆到哪里?

git - 该提交位于哪个分支?

java - 使用gradle和java在github项目中添加 "Used by"

Git - 包超出最大允许大小 - 初始提交太大