背景:
当你完成公司分配你的工作后,想自己写一写开源项目,但是公司的电脑上的git配置了公司的gitlab信息,而当你提交github的时候,不想带上公司的信息,这个时候就需要配置多个git信息。
1.进入~/.ssh文件夹
2.创建对应的公钥
创建公司的ssh key
ssh-keygen -t rsa -f ~/.ssh/gitlab_id_rsa -C “aaa@11.email”
创建github的ssh key
ssh-keygen -t rsa -f ~/.ssh/github_id_rsa -C “bbb@22.email”
3.将生成的对应的pub文件的内容粘贴到对应的代码库中
4.在~/.ssh 文件夹下创建config 文件
5.修改config文件中的内容:
# gitlab
Host https://gitlab.111.aaa.com/
HostName https://gitlab.111.aaa.com/
User name1
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitlab_id_rsa
# gitlab
Host https://github.bbb.com/
HostName https://github.bbb.com/
User name2
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
6.删除全局配置的username 和email
git config --global --unset user.name
git config --global --unset user.email
7.进入到下载的微服务目录下,设置该目录的username 和email
git config user.name “user1”
git config user.email “user1登陆GitHub的email”
这样,当你提交公司的代码到公司的gitlab上的时候,用户名就是你在公司的用户名。
当你提交代码到github上的时候,你的用户名就是github的用户名。