蓝迷梦

导航

Git 多项目多账户配置

Git 多项目多账户配置

工作中经常遇到多个项目组在不同的Gitlab等托管平台上进行代码管理,需要Git多账户的配置,经过研究,现总结如下几步:

 

1.设置不同的用户名和邮箱(不是必须的,也可以同一用户名和邮箱),命令如下:

公共配置:对所有项目生效

 

$ git config --global user.name "Your Name"
$ git config --global user.email "email@example.com"

 

单独配置:对当前项目生效

 

$ git config user.name "Your Name"
$ git config user.email "email@example.com"

 

2.生成公钥:

ssh-keygen -t rsa -C "your_email@example.com"

3.文件配置:

在c盘C:\Users\Administrator\.ssh目录 下找到生成的公钥:id_rsa.pub,私钥:id_rsa(建议给他们添加文件名称后缀,例如:id_rsa_you、id_rsa_you.pub

在当前目录下新建config文件,内容如下:

# mygit
Host 192.168.0.51 #远程Git项目主机IP
HostName 192.168.0.51
Port 2223 #远程项目主机port
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_you #刚才生成的私钥文件名
User hewei

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

# mayun
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github
User hewei

4.文件公钥:

将生成的公钥文件打开,将里面的内容粘贴到网站的ssh里面提交。

 

 

 5.代码拉取:

git clone 你的项目地址.git
例如:git clone git@github.com:hub/github.git

 

posted on 2020-12-24 11:42  蓝迷梦  阅读(632)  评论(0编辑  收藏  举报