使用多个github账号管理仓库

操作方法

  1. 打开终端或者git Bash
  2. 生成公钥和私钥

    1
    2
    $ ssh-keygen -t rsa -f ~/.ssh/id_rsa_1 -C "[email protected]" 
    $ ssh-keygen -t rsa -f ~/.ssh/id_rsa_2 -C "[email protected]"
  3. 创建config文件

    1
    touch config
  4. config文件中添加如下内容

1
2
3
4
5
6
7
8
9
10
11
# one([email protected])
Host one.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_1

# two(two@ gmail.com)
Host two.github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_2
  1. 部署SSH key
    分别登陆两个github账号,进入Personal settings –> SSH and GPG keys,将对应的.pub中的内容添加进去。
  2. 测试 SSH链接

    1
    2
    ssh -T [email protected]
    ssh -T [email protected]
  3. 进入仓库中设置用户

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # 取消全局 用户名/邮箱 配置
    git config –global –unset user.name
    git config –global –unset user.email

    # 单独设置每个repo 用户名/邮箱
    git config user.email “[email protected]
    git config user.name “one”

    git config user.email “[email protected]
    git config user.name “two”

备注

如果是使用hexo建博客,第7部应在.deploy_git文件夹中进行,或直接修改.deploy_git.git中的config文件,添加以下内容:

1
2
3
[user]
name = one
email = [email protected]

参考资料

  1. 一台电脑绑定两个github帐号教程
  2. git不同仓库不同账户解决方法

原文:大专栏  使用多个github账号管理仓库


猜你喜欢

转载自www.cnblogs.com/chinatrump/p/11606858.html