如何在一台计算机上使用多个帐户推送git

编程入门 行业动态 更新时间:2024-10-23 20:26:58
本文介绍了如何在一台计算机上使用多个帐户推送git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用两个不同的 github 帐户来分开我的学校和我的私人物品.因此,我在这里找到了方法,( 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,(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 User git IdentityFile ~/.ssh/id_rsa # Second account Host github-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: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 github/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,但是一个使用一个密钥,另一个使用另一个密钥.您的ssh配置有问题,它没有指定真正的主机是什么.

The basic technique is to configure SSH with two new virtual (ie. fake) host names. They both point at github, 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-SECONDARY User git IdentityFile ~/.ssh/id_rsa_secondary

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

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

# Second account Host github-SECONDARY HostName github 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:SECONDARY/testing.git ^^^^^^^^^^

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

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

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

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

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

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

更多推荐

如何在一台计算机上使用多个帐户推送git

本文发布于:2023-11-14 09:17:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586820.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   一台   机上   帐户   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!