github和gitlab双账号管理

公司的项目要用gitlab,然后自己的一些项目用的是github,两个账号,两个ssh keys,遂研究了下如何管理。

gitlab ssh key设置

首先gitlab的ssh key的设置请参照这篇博客:https://www.liaohuqiu.net/cn/posts/git-abc/
感觉写的十分完善。

github ssh key设置

git config --global user.name 'Kate605690919' && git config --global user.email '******@****.xx.cn'

设置github的账号和邮箱。

生成github公钥和私钥

ssh-keygen -t rsa -C "******@****.xx.cn"

这时,他会让你指定文件名,记得通过gitlab的公钥私钥区分开,比如
id_rsa_Hub这种,然后在.ssh目录中创建一个config文件,配置这github和gitlab公钥私钥的使用时机。
ps:.ssh目录在生成公钥和私钥的过程中会告诉你,,,

Host *.v.src.corp.qihoo.net
     IdentityFile C:/Users/i-limengzhao/.ssh/id_rsa
     User i-limengzhao


Host github.com
 HostName github.com
 User Kate605690919
 IdentityFile C:/Users/i-limengzhao/.ssh/id_rsa_hub

比如上面这种,告诉电脑在见到host为*.v.src.corp.qihoo.net时,使用你的gitlab账号,并使用id_rsa这个key。在遇到github的域时,使用你的github账号。

验证

i-limengzhao@limengzhao-d1 MINGW64 /e
$ git clone [email protected]:Kate605690919/Kate605690919.github.io.git
Cloning into 'Kate605690919.github.io'...
remote: Counting objects: 993, done.
Receiving objects: 100% (993/993), 821.64 KiB | 25.00 KiB/s, done.
remote: Total 993 (delta 0), reused 0 (delta 0), pack-reused 993
Resolving deltas: 100% (479/479), done.

可以发现即使是登着gitlab的账号,clone github上的东西也是可以成功的,撒花撒花~。

猜你喜欢

转载自blog.csdn.net/katecatecake/article/details/79850206