一台电脑上使用GitLab和GitHub

Problem

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

Solution

  1. 秘钥文件区分存放
  • GitLab按照默认方式存放ssh-keygen -t rsa -C "changyufei@che001.com",一路next
  • GitHub自定义存放,文件名为id_rsa_githubssh-keygen -t rsa -C "yufei.chang@outlook.com",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 "changyufei@che001.com"
  • GitHub设为local,在GitHub的工作空间下
$ git config --local user.name "yufei.chang"
$ git config --local user.email "yufei.chang@outlook.com"

报错

$ 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文件后,再执行即可

参考

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容