Github与Gitee共存

Github与Gitee共存

1
2
mkdir .ssh
cd .ssh

1.1、建立gitee秘钥

ssh-keygen -t rsa -C “xxxxx@xxxxx.com
替换正确的邮箱,按enter

1
2
Generating public/private rsa key pair.  
Enter file in which to save the key (/c/Users/FlyingHorse/.ssh/id_rsa): id_rsa_gitee

1.2、建立github秘钥

ssh-keygen -t rsa -C “xxxxx@xxxxx.com
替换正确的邮箱,按enter

1
2
Generating public/private rsa key pair.  
Enter file in which to save the key (/c/Users/FlyingHorse/.ssh/id_rsa): id_rsa_github

1.3、建立gitee工作秘钥

ssh-keygen -t rsa -C “xxxxx@xxxxx.com
替换正确的邮箱,按enter

1
2
Generating public/private rsa key pair.  
Enter file in which to save the key (/c/Users/FlyingHorse/.ssh/id_rsa): id_rsa_gitee_work

2、public key复制到gitee或github

1
2
3
type id_rsa_gitee.pub
type id_rsa_github.pub
type id_rsa_gitee_work.pub

3、创建配置解决ssh冲突

在.ssh文件夹中创建config文件,添加以下内容以区分两个ssh key

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

# work
Host work
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee_work

4、测试连接

输入

1
ssh -T git@gitee.com

若返回如下图,则gitee则连接正常

1
Welcome to Gitee.com, yourname!

输入

1
ssh -T git@github.com

若返回如下图,则github则连接正常

1
Hi yourname! You've successfully authenticated, but GitHub does not provide shell access.

5、工作账号使用

  1. 先修改下载地址
1
2
3
4
5
将下载链接中的gitee.com替换为work
# 源连接
git@gitee.com:test/aaa.git
# 新连接
git@work:test/aaa.git
  1. 程序下载
    1
    git clone git@work:test/aaa.git

微信:宏沉一笑
公众号:漫步之行

签名:Smile every day
名字:宏沉一笑
邮箱:whghcyx@outlook.com
个人网站:https://whg555.github.io



转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 whghcyx@outlook.com

文章标题:Github与Gitee共存

文章字数:390

本文作者:宏沉一笑

发布时间:2020-01-06, 09:42:24

最后更新:2023-06-19, 13:58:36

原始链接:https://whghcyx.gitee.io/2020/01/06/%E5%AE%89%E8%A3%85-2020-01-06-Github%E4%B8%8EGitee%E5%85%B1%E5%AD%98/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

目录
×

喜欢就点赞,疼爱就打赏