1. 先生成一个github的ssh key
ssh-keygen -t rsa -C "你的github邮箱" -f ~/.ssh/github_rsa
此时你的目录下面就会产生两个文件,github_rsa和github_rsa.pub
2. 将github_rsa.pub添加到github中
右上角点击头像 --> 点击settings --> 点击 SSH and GPG keys --> 点击 New SSH key --> 粘贴 id_rsa.pub
3. 在~/.ssh下创建一个config文件(如果已经存在则直接使用),分别配置公司的gitlab的ssh key和个人的github ssh key
Host 公司代码仓库地址
Hostname 公司代码仓库地址
User gitlab用户名
IdentityFile ~/.ssh/id_rsa
Host github.com
Hostname github.com
User github用户名
IdentityFile ~/.ssh/github_rsa
4. 提交代码的名称
提交代码的用户名读取的是~/.gitconfig,或者你之前设置过
git config --global user.name "公司gitlab实名"
此时传递给gitlab的时候也是这个实名。此时可以在github仓库项目文件夹下设置一个本地的用户名。
git config --local user.name "github用户名"
再进行提交就发现名字变了。
网友评论