Git 支持多账号

148 阅读1分钟

1、切换到用户\.ssh 目录下

(例如:C:\Users\user\.ssh)

2、设置用户名和邮箱

git config --global user.name "name"​
git config --global user.email "email"

3、生成ssh密钥

ssh-keygen -t rsa -C "邮箱"

4、生成ssh密钥

ssh-keygen -t rsa -C "邮箱"
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa): id_rsa_work

5、当前目录下创建config文件

# 内部GitLab仓库
# GitLab邮箱(XXXX@XXX.com)
Host gitLab 
HostName 127.0.0.1 
User git 
IdentityFile C:/Users/user/.ssh//id_rsa​
# 远程GitHub仓库​
# GitHub邮箱(diony_chen@163.com)​
Host diony_chen 
HostName github.com 
User git 
IdentityFile C:/Users/user/.ssh/id_rsa_work

6、拉取代码

git clone gitLab:user/user.git

7、测试

ssh -T git@github.com