`

git同时配置gitlab和github

    博客分类:
  • Java
 
阅读更多
本人一字一句写的,转载备注来源,谢谢
 
一、设置gitlab秘钥:
1、$ssh-keygen -t rsa -C "cjh@xxx.com"
2、回车使用默认 id_rsa取名,最后会生成id_rsa 与id_rsa.pub两个文件
3、输入密码
4、cd ~/.ssh
5、vim id_rsa.pub 拷贝到gitlab设置ssh keys
 
二、设置github秘钥:
1、$ssh-keygen -t rsa -C "cjhbest999@163.com"
2、输入id_rsa_github,如此会生成id_rsa_github 与id_rsa_github.pub两个文件
3、输入密码
4、cd ~/.ssh
5、vim id_rsa_github.pub 拷贝到github设置ssh keys
 
 如果出现 could not open a connection to your authentication agent的错误,执行如下:
    ssh-agent bash
    ssh-add id_rsa_xxx  (xxx替换具体的名字)
 
三、配置config:
1、cd ~/.ssh
2、touch config (新建config文件,没有后缀)
3、设置config内容:

#gitlab_company
Host git.xxx.com
    HostName git.xxx.com
    IdentityFile ~/.ssh/id_rsa
 
 
#github_cjhz
Host github.com
    HostName github.com
    IdentityFile ~/.ssh/id_rsa_github

Host: 别名
HostName: 托管仓库的域名或者ip
IdendityFile: 秘钥的路径
 
四、测试配置是否成功:
1、ssh -T git@git.xxx.com
2、ssh -T git@github.com
注:此处的git.xxx.com 、github.com 是config内容的Host别名,别名可以随意设置
 
五、设置用户名和邮箱
1、git config -l
     如果开始设置过如:git config --global user.name "xxx"
                                  git config --global user.email "xxx@yy.com"
     需要去掉
2、去掉全局设置:
     git config --global --unset user.name
     git config --global --unset user.email
3、设置用户和邮箱
      进入到项目的根目录:cd ~/workspace/workspace_1/wms
      git config user.name "cjh"
      git config user.email "cjh@xxx.com"
   github项目同理
 
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics