一、清除git的全局设置
通过git config --global --list来查看是否设置过。
git config --global --unset user.name "你的名字"
git config --global --unset user.email "你的邮箱"
二、生成新的 SSH keys
GitHub 的钥匙
ssh-keygen -t rsa -f ~/.ssh/id_rsa.github -C "你的邮箱"
Gitee 的钥匙
ssh-keygen -t rsa -f ~/.ssh/id_rsa.gitee -C "你的邮箱"
疯狂回车即可。
完成后会在~/.ssh / 目录下生成以下文件。
id_rsa.gitee
id_rsa.gitee.pub
id_rsa.github
id_rsa.github.pub
三、 识别 SSH keys 新的私钥
默认只读取 id_rsa,为了让 SSH 识别新的私钥,需要将新的私钥加入到 SSH agent 中
ssh-agent bash
ssh-add ~/.ssh/id_rsa.github
ssh-add ~/.ssh/id_rsa.gitee
四、多账户配置config文件
创建config文件
touch ~/.ssh/config
config 中填写的内容
# github
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa.github
# gitee
Host gitee.com
Port 22
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa.gitee
五、添加ssh
https://github.com/settings/keys
将 id_rsa.github.pub 中的内容赋值进去。
https://gitee.com/profile/sshkeys
将 id_rsa.gitee.pub 中的内容复制进去。
六、测试
···
ssh -T git@gitee.com
输入 yes 按回车
ssh -T git@github.com
输入 yes 按回车
···
七、项目配置
查看是否配置了当前项目的用户名和邮箱,git commit 和push是否需要用到这俩
需要配置当前项目的用户名和邮箱
git config user.name "你的名字"
git config user.email "你的邮箱"
配置当前的remote 为ssh
git remote -v
git remote rm origin
git remote add origin [url]
后续即可以正常add,commit, push了
参考资料: https://cloud.tencent.com/developer/beta/article/1774890
————————————————
原文链接:https://blog.csdn.net/ysh1830910726/article/details/130613531
网友评论