一台电脑同时使用GitLab和GitHub仓库

1. 用Git生成两把钥匙;

 

#GitHub的钥匙

# kingboy @ KingBoydeMacBook-Pro in ~/.ssh [7:50:33]
➜  ssh-keygen -t rsa -C "kingboy@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kingboy/.ssh/id_rsa): /Users/kingboy/.ssh/github_id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/kingboy/.ssh/github_id_rsa.
Your public key has been saved in /Users/kingboy/.ssh/github_id_rsa.pub.
The key fingerprint is:
SHA256:h6UQw+e68ncp5sidqbBpRk3WKUR04VgdJpeIlqWnfrc kingboyworld@163.com
The key's randomart image is:
+---[RSA 2048]----+
|     +=+*++o     |
|      *Oo+o      |
|     o++o..      |
|      ++++       |
|     +.oS .      |
|    ..o  .       |
|   .. ... ..     |
|    +=.+++o.     |
|   ooo===oE      |
+----[SHA256]-----+
12345678910111213141516171819202122232425

 

#gitlab

➜  ssh-keygen -t rsa -C "personal@company.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/kingboy/.ssh/id_rsa): /Users/kingboy/.ssh/gitlab_id_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/kingboy/.ssh/gitlab_id_rsa.
Your public key has been saved in /Users/kingboy/.ssh/gitlab_id_rsa.pub.
The key fingerprint is:
SHA256:h6UQw+e68ncp5sidqbBpRk3WKUR04VgdJpeIlqWnfrc personal@company.com
The key's randomart image is:
+---[RSA 2048]----+
|     +=+*++o     |
|      *Oo+o      |
|     o++o..      |
|      ++++       |
|     +.oS .      |
|    ..o  .       |
|   .. ... ..     |
|    +=.+++o.     |
|   ooo===oE      |
+----[SHA256]-----+1234567891011121314151617181920212223

注意:

Enter file in which to save the key (/Users/kingboy/.ssh/id_rsa): /Users/kingboy/.ssh/github_id_rsa

输入的是钥匙的位置和名称。github和gitlab是不同的。


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

 

github_id_rsa
github_id_rsa.pub
gitlab_id_rsa
gitlab_id_rsa.pub


将两个pub文件分别配置到github和gitlab的sshkey中

2.  编写config文件,告诉本地git到不同的国家带不同的钥匙。


  例如:


github地址:github.com
gitlab地址:gitlab.max.com12


  执行以下命令:

 


cd ~/.ssh
vim config12

config内容如下:(HostName根据自己实际需求来定)

 

#gitlab
Host gitlab
        HostName gitlab.*.com
        IdentityFile ~/.ssh/gitlab_id_rsa

#github
Host github
        HostName github.com
        IdentityFile ~/.ssh/github_id_rsa123456789

 

3. 配置仓库

例如:

github工作仓库:~/workspace/github
gitlab工作仓库:~/workspace/gitlab12

 

#gitlab
cd ~/workspace/gitlab
git init
git config --global user.name 'personal'
git config --global user.email 'personal@company.com'12345

 

#github
cd ~/workspace/github
git init
git config --local user.name 'kingboy'
git config --local user.email 'kingboy@163.com'12345

接下来在两个目录下新建或者clone项目开发即可.
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值