1:查看用户名和邮箱地址:
$ git config user.name
$ git config user.email
有时候我们需要接多个项目时,可能需要配置多个git仓库( 因为我们要配置两个git账号,之前只有一个的话用全局就可以,两个的话就要单独配置了。
一丶移除全局git用户名、邮箱、密码
$ git config --global --unset user.name
$ git config --global --unset user.email
$ git config --global --unset user.password
可以查看是否生效
$ git config --global user.name
$ git config --global user.email
$ git config --global user.password
二、配置我们的多个git账号
1生成一个公司用的SSH-Key
$ ssh-keygen -t ed25519 -C "xxxxx@company.com" -f ~/.ssh/gitee_id_rsa
2生成一个github用的SSH-Key
$ ssh-keygen -t ed25519 -C "xxxxx@qq.com" -f ~/.ssh/github_id_rsa
3在 ~/.ssh 目录下新建一个config文件,并编辑下面内容
$ touch config
$ vim config
config内容如下:
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/github_id_rsa
分别查看公钥:
$ cat gitee_id_rsa.pub
$ cat github_id_rsa.pub
4将公匙内容分别复制到gitee(公司git服务器上)和github上,后执行ssh命令分别测试
$ ssh -T git@gitee.com
$ ssh -T git@github.com
这里以gitee为例(执行上面命令后,输入yes),成功的话会返回下图内容
参考:https://gitee.com/help/articles/4229#article-header0