清除git的全局配置

查看全局配置

git config --global --list

清除全局配置

git config --global --unset user.name "test"

git config --global --unset user.email [email protected]

生成github和gitee的ssh key

生成github的ssh key

ssh-keygen -t rsa -C 'github邮箱号' -f ~/.ssh/id_rsa_github

一路回车即可。

最后会在~/.ssh/目录下生成id_rsa_github(私钥)和id_rsa_github.pub(公钥)。

生成gitee的ssh key

ssh-keygen -t rsa -C 'gitee邮箱号' -f ~/.ssh/id_rsa_gitee

一路回车即可。

最后会在~/.ssh/目录下生成id_rsa_gitee(私钥)和id_rsa_gitee.pub(公钥)。

分别登录gitee、github添加SSH KEY

将github和gitee的公钥填到github和gitee设置中的ssh key中

配置git的config

打开git bash,在.ssh目录下,新建并编辑config文件,写入一下内容:

1
2
3
4
5
6
7
8
9
10
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_gitee
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa_github

测试是否成功

ssh -T [email protected]

ssh -T [email protected]

如出现下列输出,则说明配置成功:

Hi XXXXX! You've successfully authenticated, but GitHub does not provide shell access.


删除了全局配置后,在执行git commit时会提示一下信息:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Author identity unknown

*** Please tell me who you are.

Run

git config --global user.email "[email protected]"
git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'admin@DESKTOP-XXXXX.(none)')

这种情况需要按照上述提示配置目前这个仓库下的用户密码即可,即执行:

1
2
git config  user.name "test"
git config user.email [email protected]

然后再执行git commit就可以了


参考

Git同时配置GitHub和Gitee

[人工智能-深度学习-75]:环境 - Windows配置Github、Gitee共存的Git环境