zl程序教程

您现在的位置是:首页 >  工具

当前栏目

Git github多帐号配置

2023-09-27 14:25:33 时间

设现在有两个帐号: aaa、bbb
对应的邮箱地址为: 123@qq.com、456@qq.com
对应的网页地址为: github.com/aaa、github.com/bbb

  1. 使用以下命令在.ssh文件夹下创建 key

    ssh-keygen -t ed25519 -C "123@qq.com" -f ~/.ssh/id_ed25519_aaa
    ssh-keygen -t ed25519 -C "456@qq.com" -f ~/.ssh/id_ed25519_bbb
    
  2. 使用以下命令快速打开.ssh文件夹

    :: MAC系统
    open ~/.ssh
    
    :: Windows系统, 也可直接打开 C:\Users\Administrator\.ssh
    start ~/.ssh
    
  3. .ssh文件夹下,创建 config 文件(注意无后缀名,UTF-8编码)

    Host aaa
    HostName github.com
    User 123@qq.com
    IdentityFile ~/.ssh/id_ed25519_aaa
    
    Host bbb
    HostName github.com
    User 456@qq.com
    IdentityFile ~/.ssh/id_ed25519_bbb
    
  4. 添加远程仓库地址
    假设远程仓库的地址为:
    git@github.com:aaa/test.git
    git@github.com:bbb/test.git
    需要把其中的github.com替换为configHost的值,如:
    git@aaa:aaa/test.git
    git@aaa:bbb/test.git
    添加远程仓库的命令对应修改为:

    git remote add origin git@aaa:aaa/test.git
    git remote add origin git@bbb:bbb/test.git