如何在一台计算机上使用多个帐户推送git [英] How can I push git with multiple accounts on one machine

查看:60
本文介绍了如何在一台计算机上使用多个帐户推送git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用两个不同的 github 帐户来分开我的学校和我的私人物品.因此,我在这里找到了方法,( https://youtu.be/fnSRBRiQIU8 )

I want to use two different github accounts to separate my school and my personal things. So I found the methods here,(https://youtu.be/fnSRBRiQIU8)

我在每个帐户上成功添加了两个ssh密钥,这是我的〜/.ssh/config 文件

I successfully added two ssh keys on each account and this is my ~/.ssh/config file

# Default account
Host github.com
    User git
    IdentityFile ~/.ssh/id_rsa
# Second account
Host github.com-SECONDARY
    User git
    IdentityFile ~/.ssh/id_rsa_secondary

我试图推动它,但是没有运气.

I tried to push it but did not have luck.

在youtube视频及其书面说明中,

In the youtube video and its written instruction describe,

1. git remote add origin git@github.com:SECONDARY/testing.git
2. git push -u origin master

我认为这是旧方法,所以我做了这样的新方法

I thought it is old way, so I did new way like this

3. git remote add origin https://github.com/SECONDARYusername/testing.git
4. git push -u origin master

然后我收到了此错误消息

Then I got this error message

fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

第1行和第3行不相等吗?还有其他方法可以在一台计算机上使用两个帐户吗?谢谢!

Aren't line 1 and 3 equivalent? Is there other method that I can use two accounts on one machine? Thanks!

推荐答案

基本技术是使用两个新的虚拟(即假)主机名配置SSH.它们都指向github.com,但是一个使用一个密钥,另一个使用另一个密钥.您的ssh配置有问题,它没有指定真正的主机是什么.

The basic technique is to configure SSH with two new virtual (ie. fake) host names. They both point at github.com, but one uses one key and the other use the other. Your ssh config has a problem, it doesn't specify what the real host is.

# Second account
Host github.com-SECONDARY
    User git
    IdentityFile ~/.ssh/id_rsa_secondary

说当您尝试连接到github.com-SECONDARY时,请使用〜/.ssh/id_rsa_secondary中的ssh密钥".但是github.com-SECONDARY不是真实的.您需要通过添加 HostName 行来告诉ssh.

That says "when you try to connect to github.com-SECONDARY, use the ssh key in ~/.ssh/id_rsa_secondary". But github.com-SECONDARY isn't real. You need to tell ssh that by adding a HostName line.

# Second account
Host github.com-SECONDARY
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_secondary

那是第一个问题.

第二个是您不在遥控器中使用该主机名.

The second is you're not using that hostname in your remotes.

git remote add origin git@github.com:SECONDARY/testing.git
                          ^^^^^^^^^^

这是主机名部分.像这样应该是 github.com-SECONDARY .

That's the hostname part. It should be github.com-SECONDARY like so.

git remote add origin git@github.com-SECONDARY:SECONDARY/testing.git

然后ssh将知道为 github.com-SECONDARY 虚拟主机使用您的特殊配置.

Then ssh will know to use your special config for the github.com-SECONDARY virtual host.

"多个GitHub帐户的问答中,有一个更好的信息& SSH Config ".

这篇关于如何在一台计算机上使用多个帐户推送git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆