本地使用 GitHub 和 Gitee 时连接服务器错误及代理配置冲突解决
解决了在本地同时使用 GitHub 和 Gitee 时,因全局代理配置导致的 Gitee 连接失败问题。错误提示显示无法连接到 127.0.0.1:7898。主要原因是 Git 继承了为 GitHub 设置的代理配置,而 Gitee 需要直连。解决方案包括取消全局代理设置、针对特定域名取消代理、检查环境变量或配置代理软件规则模式。推荐使用 SSH 替代 HTTPS 或按域名区分代理策略。

解决了在本地同时使用 GitHub 和 Gitee 时,因全局代理配置导致的 Gitee 连接失败问题。错误提示显示无法连接到 127.0.0.1:7898。主要原因是 Git 继承了为 GitHub 设置的代理配置,而 Gitee 需要直连。解决方案包括取消全局代理设置、针对特定域名取消代理、检查环境变量或配置代理软件规则模式。推荐使用 SSH 替代 HTTPS 或按域名区分代理策略。

最近在使用 GitHub 拉取代码后,隔天推送 Gitee 代码时提示无法连接到服务器,并显示本地 IP 地址 127.0.0.1 及端口号 7898。
git.exe clone --progress -v -- "https://gitee.com/xxx/xxx.git" "D:\github\xxx"
Cloning into 'D:\github\xxx'...
fatal: unable to access 'https://gitee.com/xxx/xxx.git/': Failed to connect to 127.0.0.1 port 7898 after 2116 ms: Couldn't connect to server
git 未能顺利结束 (退出码 128) (2250 ms @ 2025/9/24 14:47:30)
该问题通常是因为 Git 试图通过本地 7898 端口的代理服务器连接 Gitee,但代理服务未运行。以下是几种解决方案:
# 取消全局代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy
# 或者只为 Gitee 域名取消代理
git config --global http.https://gitee.com.proxy ""
git config --global https.https://gitee.com.proxy ""
如果您确实需要使用代理,请确保代理软件正在运行:
# 1. 先取消代理设置
git config --global --unset http.proxy
git config --global --unset https.proxy
# 2. 重新克隆项目
git clone https://gitee.com/xiao555/centerinfo.git "D:\github\centerinfo"
有时候代理设置可能来自环境变量:
# 检查环境变量
echo $HTTP_PROXY
echo $HTTPS_PROXY
echo $http_proxy
echo $https_proxy
# 如果设置了,可以临时取消
set HTTP_PROXY=
set HTTPS_PROXY=
# 打开命令提示符或 Git Bash,依次执行:
git config --global --unset http.proxy
git config --global --unset https.proxy
git clone https://gitee.com/xiao555/centerinfo.git "D:\github\centerinfo"
# 查看当前 Git 配置
git config --global --list
# 如果看到 proxy 设置,就取消它
执行完上述命令后,重新运行克隆命令:
git clone https://gitee.com/xiao555/centerinfo.git "D:\github\centerinfo"
如果您的网络环境必须使用代理,请:
GitHub 和 Gitee 本身不会冲突,但在使用过程中可能会出现以下几种情况:
# 为 GitHub 设置了代理,但 Gitee 也走代理导致失败
git config --global http.proxy http://127.0.0.1:7898
git config --global https.proxy http://127.0.0.1:7898
同一个 SSH 密钥可能在不同平台权限不同,GitHub 和 Gitee 可能使用相同的 SSH 密钥,但配置不同。
# 只为 GitHub 设置代理
git config --global http.https://github.com.proxy http://127.0.0.1:7898
git config --global https.https://github.com.proxy http://127.0.0.1:7898
# Gitee 直连(取消代理)
git config --global http.https://gitee.com.proxy ""
git config --global https.https://gitee.com.proxy ""
在代理软件(Clash/V2Ray)中设置:
# 为特定仓库设置单独配置
cd /path/to/gitee-project
git config http.proxy ""
# Gitee 项目直连
cd /path/to/github-project
git config http.proxy http://127.0.0.1:7898
# GitHub 项目走代理
# 使用 SSH 连接可以避免 HTTP/HTTPS 代理问题
git clone [email protected]:xiao555/centerinfo.git
git clone [email protected]:username/repo.git
# 查看所有 Git 配置
git config --global --list
# 查看特定配置
git config --global http.proxy
git config --global https.proxy
# Windows 凭据管理器清理
# 或使用 Git 命令清理
git credential-manager reject https://gitee.com
git credential-manager reject https://github.com
# 取消全局代理
git config --global --unset http.proxy
git config --global --unset https.proxy
# 按需为国外网站设置代理
git config --global http.https://github.com.proxy http://127.0.0.1:7898
git config --global http.https://gitlab.com.proxy http://127.0.0.1:7898
# 国内网站直连
git config --global http.https://gitee.com.proxy ""
# 测试 Gitee 连接(应该直连)
git ls-remote https://gitee.com/xiao555/centerinfo.git
# 测试 GitHub 连接(应该走代理)
git ls-remote https://github.com/someuser/somerepo.git

微信公众号「极客日志」,在微信中扫描左侧二维码关注。展示文案:极客日志 zeeklog
将字符串编码和解码为其 Base64 格式表示形式即可。 在线工具,Base64 字符串编码/解码在线工具,online
将字符串、文件或图像转换为其 Base64 表示形式。 在线工具,Base64 文件转换器在线工具,online
将 Markdown(GFM)转为 HTML 片段,浏览器内 marked 解析;与 HTML 转 Markdown 互为补充。 在线工具,Markdown 转 HTML在线工具,online
将 HTML 片段转为 GitHub Flavored Markdown,支持标题、列表、链接、代码块与表格等;浏览器内处理,可链接预填。 在线工具,HTML 转 Markdown在线工具,online
通过删除不必要的空白来缩小和压缩JSON。 在线工具,JSON 压缩在线工具,online
将JSON字符串修饰为友好的可读格式。 在线工具,JSON美化和格式化在线工具,online