Git 无法访问 GitHub(Recv failure: Connection was reset)问题解决教程

Git 无法访问 GitHub(Recv failure: Connection was reset)问题解决教程

在使用 Git 访问 GitHub 仓库时,如果遇到以下报错:

复制代码
fatal: unable to access '[https://github.com/xxx/xxx.git/](https://github.com/xxx/xxx.git/)': Recv failure: Connection was reset

说明本地 Git 无法通过 HTTPS 协议访问 GitHub。以下是排查与解决方法。


1. 浏览器能访问但 Git 不能

如果浏览器可以正常打开 https://github.com,但 Git 命令行失败,大概率是因为:

  • 浏览器走了代理
  • Git 命令行没有走代理

2. 为 Git 配置全局代理

如果你的代理运行在本地 127.0.0.1:7890,可以这样设置:

bash 复制代码
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

测试是否成功:

bash 复制代码
git ls-remote https://github.com/用户名/仓库名.git

如果能返回 HEAD 和 refs,说明连通了。


3. 只为 GitHub 配置代理

如果不想所有 Git 都走代理,可以只针对 GitHub:

bash 复制代码
git config --global http.https://github.com.proxy http://127.0.0.1:7890

4. 清除代理配置

如果代理不可用,Git 会报错。可以取消配置:

bash 复制代码
git config --global --unset http.proxy
git config --global --unset https.proxy

5. 改用 SSH 连接(推荐)

HTTPS 在某些网络环境下不稳定,SSH 更加可靠:

  1. 生成 SSH key(如果还没有):

    bash 复制代码
    ssh-keygen -t ed25519 -C "your_email@example.com"
  2. ~/.ssh/id_ed25519.pub 内容添加到 GitHub

    👉 GitHub SSH key 设置

  3. 修改仓库远程地址:

    bash 复制代码
    git remote set-url origin git@github.com:用户名/仓库名.git
  4. 测试:

    bash 复制代码
    ssh -T git@github.com

    成功会提示:

    复制代码
    Hi your-username! You've successfully authenticated, but GitHub does not provide shell access.

6. 常用检查命令

  • 查看代理配置:

    bash 复制代码
    git config --global -l
  • 测试 GitHub 连接:

    bash 复制代码
    curl -v https://github.com

总结

  • 能上 GitHub 但 Git 报错 → 代理问题
  • 解决方案 1:给 Git 配置代理
  • 解决方案 2:改用 SSH

推荐使用 SSH 方式,更加稳定,不需要额外代理配置。

相关推荐
量化小c19 小时前
一行代码查 BTCUSDT 和 AAPL 最新价?QuantDash 统一多市场实时行情接口实战
后端·算法·github
峰向AI19 小时前
Anthropic 工程师每天都在用的小工具:核心代码只有四行,26万次浏览
github
fthux19 小时前
被主流遮住的世界:那些不常见却值得认识的编程语言
人工智能·ai·开源·github
番茄不是西红柿kk20 小时前
deepseek-harness跨平台桌面端二开项目(附git仓库地址+安装包)
git·agent·codex·deepseek·deepseekharness
高频因子挖掘机1 天前
QuantDash 成交量单位统一实战:从“手”到“股”的跨市场量化数据清洗全流程
后端·算法·github
CoderJia程序员甲1 天前
GitHub 热榜项目 - 周榜(2026-08-22)
ai·大模型·llm·github·ai教程
丰锋ff1 天前
Github使用教程
github
leoZ2311 天前
10-Git 仓库蒸馏术:从代码仓库到 OpenClaw 虚拟人-蒸馏工具链
大数据·git·深度学习·神经网络·目标检测·elasticsearch·lstm
fpcc1 天前
工具使用—git diff命令分析说明
git·工具
console.log('npc')2 天前
Git 删除指定提交记录操作指南
git