Mac配置GitLab和GitHub账户

如何在一台电脑上配置GitLab账号和GitHub账号【mac】

前言

作为一个开发者,在我们的工作中,经常会想要维护一个自己的代码库和工作中用的代码库,但是配置它们又是一项比较复杂麻烦的事情,下面分享给大家一些自己配置过程中的步骤以及注意事项。

配置步骤

一、生成SSH密钥 & 配置

  1. 在Terminal终端中使用ssh-keygen -t rsa -C "公司邮箱地址"生成对应的gitlab密钥:id_rsa和id_rsa.pub
  2. 将gitlab公钥即id_rsa.pub中的内容配置到公司的gitlab上
  3. 在Terminal终端中使用ssh-keygen -t rsa -C “github地址” -f ~/.ssh/github_rsa生成对应的github密钥:github_rsa和github_rsa.pub
  4. 将github公钥即github_rsa.pub中的内容配置到自己的github上
  5. 进入密钥生成的位置,创建一个config文件,添加配置:

我们在Terminal终端对Git进行了一系列的配置:

// 进入ssh文件夹
xuhao@bogon ~$ cd ~
xuhao@bogon ~$ cd .ssh
xuhao@bogon .ssh$ ssh-keygen -t rsa -C "你的工作邮箱"
// 两次回车直接生成工作邮箱相关密钥
xuhao@bogon .ssh$ ls
id_rsa     id_rsa.pub

xuhao@bogon .ssh$ ssh-keygen -t rsa -C "你的个人邮箱" -f ~/.ssh/github_rsa
// 两次回车直接生成个人邮箱相关密钥
xuhao@bogon .ssh$ ls
github_rsa     github_rsa.pub id_rsa         id_rsa.pub

// 创建 & 配置 config文件,管理ssh会话
xuhao@bogon .ssh$ open ./
xuhao@bogon .ssh$ vim config
// config文件主要内容:
# gitlab
Host gitlab 别名
   HostName  你的工作代码库的host域名
   User git
   IdentityFile ~/.ssh/id_rsa
# github
Host github.com
   HostName github.com
   User git
   IdentityFile ~/.ssh/github_rsa

xuhao@bogon .ssh$ ls
config         github_rsa     github_rsa.pub id_rsa         id_rsa.pub

二、测试SSH连接

xuhao@bogon .ssh$ ssh -T git@github.com
The authenticity of host 'github.com (xxxxxxxxxxxx)' can't be established.
RSA key fingerprint is SHA256: xxxxxxxxxxxxxxxxxxxxxxxxxx
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,xxxxxxxxxxx' (RSA) to the list of known hosts.
Hi 你的github账号名! You've successfully authenticated, but GitHub does not provide shell access.
xuhao@bogon .ssh$ ssh -T git@github.com
Hi 你的github账号名! You've successfully authenticated, but GitHub does not provide shell access.
xuhao@bogon .ssh$ 
// 恭喜你!你的github的密钥已经配置 & 联通成功。

xuhao@bogon .ssh$ ssh -T git@gitlab
The authenticity of host '你的工作代码库域名,你的工作代码库ip地址' can't be established.
RSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '你的工作代码库域名,你的工作代码库ip地址' (RSA) to the list of known hosts.
Welcome to GitLab, 你的工作代码库账号名!
xuhao@bogon .ssh$ ssh -T git@gitlab
Welcome to GitLab, 你的工作代码库账号名!
// 恭喜你!你的gitlab工作代码库的密钥已经配置 & 联通成功。

三、本地配置

// 全局配置
$ git config --global user.name 'gitlab账号名'   
$ git config --global user.email '公司账号邮箱' 

// 本地配置
$ git config --local user.name '个人github账号名' 
$ git config --local user.email '个人github账号邮箱'

总结

至此,你的电脑上已经完成了对gitlab和github的配置联通工作。是不是,其实也没有那么麻烦呢,哈哈哈~ 亲爱的小伙伴们,如果觉得对你开发工作有帮助的话,请记得收藏点赞哦~

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值