windows环境同时配置github | gitee | gitlab

1. 清除 git 的全局设置(针对已安装 git)

新安装 git 则跳过。

如果不确定当前电脑是否安装过,可以用 git config --global --list 进行查看你是否设置

  1. 查看配置列表
git config --global --list
$ git config --global user.name "你的名字"
$ git config --global user.email  "你的邮箱"
  1. 必须删除该全局设置
$ git config --global --unset user.name "你的名字"
$ git config --global --unset user.email "你的邮箱"

2. 生成新的 SSH keys

随便打开找个文件夹,git bash here 打开bash 命令窗口

1. github

ssh-keygen -t rsa -f ~/.ssh/id_rsa_github -C "关联的邮箱地址"

然后连续三次enter就可以了

2. gitee

ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitee -C "关联的邮箱地址"

然后连续三次enter就可以了

3. gitlab

ssh-keygen -t rsa -f ~/.ssh/id_rsa_gitlab -C "关联的邮箱地址"

然后连续三次enter就可以了

4. 查看生成的公钥私钥文件
在这里插入图片描述

5. 新建config文件

# gitlab
    Host git.xxx.cn
    HostName git.xxx.cn
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitlab
    User git
# gitee
    Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_gitee
    User git
# github
    Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/id_rsa_github
    User git

再分别将生成的以.pub文件的里面的内容(公钥)复制到对应的ssh key中即可

6. 检查是否配置完毕
以github为例,其他类似

$ ssh -T git@github.com
Hi robinsun2018! You've successfully authenticated, but GitHub does not provide shell access.

看到 successfully 字眼就说明配置成功了

最后,如果看完对你有所帮助,不要吝啬关注 / 点赞 / 收藏哟,感谢感谢~