【Github】一台电脑使用多个 Github 账户

账户所用 SSH 秘钥生成

$ cd ~/.ssh
$ ls
id_rsa id_rsa.pub

$ ssh-keygen -t rsa -c [mail] -f [filename]

将生成的 SSH 秘钥登录到 Github 账号中

登录 Github 账户,进入 https://github.com/settings/ssh
「Add SSH Key」中,将新生成的 .pub 秘钥粘贴至输入框

编辑 ~/.ssh/config

对文件 ~/.ssh/config 进行编辑(如文件不存在则新建一个):

Host github.com
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/id_rsa  # 主账号所使用的 SSH 秘钥
  TCPKeepAlive yes
  IdentitiesOnly yes
Host github.com.sub  # (1) 副账号:可任意命名
  HostName github.com
  User git
  Port 22
  IdentityFile ~/.ssh/id_rsa_sub  # (2) 副账号所使用 SSH 秘钥路径
  TCPKeepAlive yes
  IdentitiesOnly yes

使用副账号 clone 远程仓库

正常情况下 git clonegit remote add

$ git clone git@github.com:xxx/multi-account-sample.git
$ git remote add origin git@github.com:xxx/multi-account-sample.git

在使用副账号时则将@之后的部分进行修改

$ git clone git@github.com.sub:xxx/multi-account-sample.git
$ git remote add origin git@github.com.sub:xxx/multi-account-sample.git

设置副账号的 user.nameuser.email

在副账号所管理的文件下,执行一次如下命令:

$ git config user.name [sub_account.user_name]
$ git config user.email [sub_account.email]

更多内容请翻看我的个人博客:http://achillessatan.github.io/

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

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,027评论 19 139
  • 第一章 安装Git工具 下载GitHub for Windows,直接点击安装,安装完成后,可以看到“Git Sh...
    不圆的石头阅读 11,955评论 5 63
  • Git的使用 首先登录https://git.oschina.net,如没有账号进行注册. Git简单介绍 Git...
    Sunney阅读 674评论 0 2
  • 男:媳妇,在么 女:嗯 男:媳妇,我刚刚找到 一个很好看的情侣头像 男:这个头像我们用很久了 要不换一个吧 女:不...
    琉璃陌情阅读 235评论 0 0
  • 根据书上所说。 冥想,脱离三元次世界,平静不受任何影响,不做任何复杂的思考,回归内心。达到忘我的境界。
    小强e阅读 228评论 0 0