一台电脑上使用GitLab和GitHub

Problem

工作的代码都放到公司的GitLab中,个人平时也会是会GitHub,如果按照默认的配置方法,两者会冲突。

Solution

  1. 秘钥文件区分存放
  • GitLab按照默认方式存放ssh-keygen -t rsa -C "[email protected]",一路next
  • GitHub自定义存放,文件名为id_rsa_githubssh-keygen -t rsa -C "[email protected]",Enter file in which to save the key (/c/Users/bili/.ssh/id_rsa): /c/Users/bili/.ssh/id_rsa_github
  • 此时,~/.ssh目录下应该有4个文件
bili@c190198 MINGW64 ~/.ssh
$ ls
id_rsa  id_rsa.pub  id_rsa_github  id_rsa_github.pub
  1. 配置ssh key,将pub文件中的内容放到GitLab和GitHub中
  2. ~/.ssh下添加config配置文件
Host gitlab
    HostName [IP or host]        
    IdentityFile ~/.ssh/id_rsa
Host github
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github
  1. 设置user.name和user.email
  • 工作中GitLab使用频繁,将GitLab设置为global,在任意目录下
$ git config --global user.name "changyufei"
$ git config --global user.email "[email protected]"
  • GitHub设为local,在GitHub的工作空间下
$ git config --local user.name "yufei.chang"
$ git config --local user.email "[email protected]"

报错

$ git config --local user.name "yufei.chang"
error: could not lock config file .git/config: No such file or directory
error: could not lock config file .git/config: No such file or directory

在该目录下创建.git/config文件后,再执行即可

参考

你可能感兴趣的:(一台电脑上使用GitLab和GitHub)