Git同时配置Gitee和GitHub

1、清除旧用户

如果之前曾设置过会在TortoiseGit 软件中查看到,如图:

可以使用下面的指令清除全局设置【推荐使用】:

bash 复制代码
git config --global --unset user.name "你的名字"
 git config --global --unset user.email "你的邮箱"

举个栗子:

bash 复制代码
git config --global --unset user.name "qiandu"
git config --global --unset user.email "2013498006@qq.com"

或者借助TortoiseGit

查看是否清除成功

bash 复制代码
git config --global --list

如果没有出现user和email,那就代表全局设置清除成功!

2、设置用户

bash 复制代码
git config --global user.name   "你的名字"
git config --global user.email  "你的邮箱"

举个栗子:

bash 复制代码
git config --global user.name   "qiandu"
git config --global user.email  "2013498006@qq.com"

或者

3、生成SSH公钥和私钥

注意 邮箱改成自己的!!!!

bash 复制代码
ssh-keygen -t rsa -C '2013498006@qq.com' -f ~/.ssh/gitee_id_rsa
bash 复制代码
ssh-keygen -t rsa -C '2013498006@qq.com' -f ~/.ssh/github_id_rsa

注意输入生成SSH-key指令后,需要按回车3次,表示empty,即"空","空"代表没有密码。

4、新建配置文件

在 ~/.ssh 目录【C:\Users\用户名.ssh】下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

bash 复制代码
# github
Host github.com
    HostName github.com
    User git
    Port 443
    IdentityFile ~/.ssh/github_id_rsa

# gitee
Host gitee.com
    HostName gitee.com
    User git
    Port 22
    IdentityFile ~/.ssh/gitee_id_rsa
bash 复制代码
ssh-add ~/.ssh/gitee_id_rsa
ssh-add ~/.ssh/github_id_rsa

确认ssh-agent进程是否在运行:运行 eval $(ssh-agent) 来启动或重新启动认证代理。

bash 复制代码
 eval $(ssh-agent)

添加完毕后,可以通过执行下述代码进行验证。

bash 复制代码
ssh-add -l

5、添加对应的公钥到Gitee和GitHub

Gitee公钥 :gitee_id_rsa.pub
GitHub公钥 :github_id_rsa.pub

6、测试

bash 复制代码
ssh -T git@gitee.com
ssh -T git@gitub.com
相关推荐
Maya动画技术14 分钟前
github-2fa认证是啥意思
github·2fa恢复码使用方法
怪侠_岭南一只猿16 分钟前
爬虫阶段二实战练习题一:模拟登录github获取个人信息复盘
爬虫·github
YMWM_27 分钟前
linux命令行测试是否可以访问google、github、huggingface
linux·运维·github
WangJunXiang633 分钟前
系统安全及应用
安全·github·系统安全
zhensherlock34 分钟前
Protocol Launcher 系列:一键唤起 VSCodium 智能 IDE
javascript·ide·vscode·typescript·开源·编辑器·github
AAA小肥杨1 小时前
OpenClaw 和 GitHub 自动化,用于 PR 审核和 CI 监控
人工智能·ci/cd·自动化·大模型·github·openclaw
白白白飘1 小时前
GitHub上运行开源项目(小白友好版)
开源·github
李同学Lino1 小时前
拒绝 500 元智商税!AutoClaw 零门槛安装教程,手把手教你低成本“喂龙虾”
人工智能·ai·github·openclaw·autoclaw
AI精钢2 小时前
OpenClaw + GitHub Copilot GPT-5.4 技术修复指南
gpt·github·copilot·github copilot·ai agent·openclaw·gpt-5.4
kyriewen2 小时前
别再直接 git push 了!这个"魔法"参数让你的代码质量翻倍
前端·git·命令行