Bootstrap

Git同时配置Gitee和GitHub

Git同时配置Gitee和GitHub

此方法是用一台电脑,两个邮箱,分别配置Gitee和Github。

1 清除git的全局设置

以下所有命令建议在 git bash 中完成。

如果是之前没设置过的,就不用清除了,**这一步需要再探索,本人没有清除,似乎也可以实现。**附上设置全局属性的命令:

git config --global user.name "名字"                      
git config --global user.email "邮箱"

执行后会在windows生成C:\Users\lenovo\.gitconfig文件
注:--global 表示全局属性,所有的git项目都会共用属性。
设置本地机器默认commit的昵称与Email. 请使用有意义的名字与email.

可以通过git config --global --list来查看是否设置过。

git config --global --unset user.name "你的名字"
git config --global --unset user.email "你的邮箱"

2 生成新的 SSH keys

2.1 GitHub 的钥匙

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "邮箱一"

回车即可。

2.2 Gitee 的钥匙

邮箱换一个。不要跟上面相同就行了。

ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "邮箱二"

回车即可。

完成后会在~/.ssh / 目录下生成以下文件。

  • id_rsa.github
  • id_rsa.github.pub
  • id_rsa.gitee
  • id_rsa.gitee.pub

3 识别 SSH keys 新的私钥

默认只读取 id_rsa,为了让 SSH 识别新的私钥,需要将新的私钥加入到 SSH agent 中。这一步也需要再探索一下,我没有设置也可以成功。

ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee

4 多账号配置 config 文件

创建config文件:

touch ~/.ssh/config 

config 中填写的内容:

#Default gitHub user Self
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa.github

# gitee
Host gitee.com
    Port 22
    HostName gitee.com
    User git
    IdentityFile ~/.ssh/id_rsa.gitee

5 添加 ssh

分别添加SSH到Gitee和Github:

Github:
https://github.com/settings/keys
id_rsa.github.pub 中的内容填进去,起名的话随意。

Gitee:
https://gitee.com/profile/sshkeys
id_rsa.gitee.pub 中的内容填进去,起名的话随意。

6 测试成功

ssh -T git@gitee.com
ssh -T git@github.com

在这里插入图片描述

原文

7 探索

是否可以使用同一个邮箱为Gitee、Github生成SSH公钥。


声明:
本篇文章为学习笔记,若作品涉及版权或存在其他问题,请联系我删除。
谢谢浏览!
;