一台电脑多git账号:

1.移除git全局配置

git config --global --unset user.name
git config --global --unset user.email

2.生成github并部署

ssh-keygen -t rsa -C “yongjun.zhang@email1.com”

2.1 生成此账号对应的公钥和私钥

3.生成gitee并部署

ssh-keygen -t rsa -f ~/.ssh/id_rsa2 -C “yongjun.zhang@email2.com”

3.1 生成第二个账号对应的公钥和私钥 注意区别不要覆盖前一个账号的信息

4.config文件

在.ssh目录下新建config文件(无需后缀),配置如下

配置user1

Host github
HostName github.com
IdentityFile C:\\Users\\yozha\\.ssh\\id_rsa
PreferredAuthentications publickey
User yongjun.zhang@email1.com

配置user2

Host coding
HostName gitee.com
IdentityFile C:\\Users\\yozha\\.ssh\\id_rsa2
PreferredAuthentications publickey
User yongjun.zhang@email2.com

PS: 以上4步之后即可正常操作,此时git clone时需注意:
git clone git@github.com:*******.git 需将 @与:中间的网址换做别名 github
同理 gitee.com需要更换为 coding

将本地代码推送远端仓库

git remote add origin git@github.com:your.git
git branch -M main
git push -u origin main

Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐