当前位置:   article > 正文

Git 同时配置Gitee和GitHub_gitee和github一起用

gitee和github一起用

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

账号信息

清除git的全局设置

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

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

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

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

可以通过来以下命令查看是否设置过。

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

生成新的 SSH keys

GitHub 的钥匙

ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "xxxxxxx@qq.com"
  • 1

回车即可。

Gitee 的钥匙

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

ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "xxxxxxx@qq.com"
  • 1

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

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

识别 SSH keys 新的私钥

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

ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee 
  • 1
  • 2
  • 3

多账号配置 config 文件

创建config文件:

touch ~/.ssh/config 
  • 1

文件位置:C:\Users\wenbo.ssh

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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

添加 ssh

分别添加SSH到Gitee和Github:

Github:

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

Gitee:

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

测试成功

ssh -T git@gitee.com
ssh -T git@github.com
  • 1
  • 2

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/秋刀鱼在做梦/article/detail/773286
推荐阅读
相关标签
  

闽ICP备14008679号