所以这是一个非常具体的用例。如果有任何 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-alice
和 github-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