环境准备git clone https://github.com/young
你遇到的错误:
fatal: unable to access 'https://github.com/youngyangyang04/Test-Automation-Framework.git/': HTTP/2 stream 1 was not closed cleanly before end of the underlying stream
是一个网络层问题,常见于 HTTPS 请求时连接异常中断,尤其在使用 git clone 时。
✅ 一、错误原因分析
这个错误通常由以下原因之一引起:
🔌 网络不稳定(尤其是国内) | GitHub 在国内访问有时不稳定,尤其使用 HTTP/2 时容易断连 |
🌐 代理/防火墙干扰 | 企业网络、校园网、或某些路由器会拦截或中断 HTTPS 流 |
🔁 Git 的 HTTP/2 配置问题 | 某些 Git 版本在 HTTP/2 上有 Bug 或兼容性问题 |
🛠️ 本地 Git 配置异常 | 例如缓存、证书问题 |
✅ 二、解决方案(按优先级排序)
✅ 方法 1:关闭 HTTP/2,强制使用 HTTP/1.1(推荐!)
这是最有效的解决方式,因为很多网络环境对 HTTP/2 支持不好。
git config --global http.version HTTP/1.1
✅ 这会强制 Git 使用更稳定的 HTTP/1.1 协议,避免 HTTP/2 流中断问题。
然后重试克隆:
git clone https://github.com/youngyangyang04/Test-Automation-Framework.git
✅ 方法 2:使用 SSH 方式克隆(更稳定)
- 先生成 SSH 密钥(如果没有):
ssh-keygen -t ed25519 -C "your_email@example.com"
- 添加密钥到 SSH Agent:
eval $(ssh-agent -s) ssh-add ~/.ssh/id_ed25519
- 复制公钥到 GitHub:查看公钥:cat ~/.ssh/id_ed25519.pub粘贴到 GitHub → Settings → SSH and GPG keys → New SSH key
- 用 SSH 克隆:
git clone **********:youngyangyang04/Test-Automation-Framework.git
✅ SSH 通常比 HTTPS 更稳定,尤其在防火墙多的环境下。
✅ 方法 3:使用国内镜像或代理(适合网络差)
方式 A:使用 GitHub 加速代理(如 ghproxy.com)
git clone https://ghproxy.com/https://github.com/youngyangyang04/Test-Automation-Framework.git
🌐
ghproxy.com是一个 GitHub 代理服务,可绕过墙和网络问题。
方式 B:使用 git config 设置代理(如果你有代理)
git config --global http.proxy http://proxy.company.com:8080 git config --global https.proxy https://proxy.company.com:8080
使用后记得清理:
git config --global --unset http.proxy git config --global --unset https.proxy
✅ 方法 4:重试 + 增加超时时间(临时方案)
git config --global http.postBuffer 524288000 git config --global http.lowSpeedLimit 0 git config --global http.lowSpeedTime 999999
然后重试克隆。
✅ 方法 5:更换网络环境(最简单)
- 换个 WiFi(比如手机热点)
- 使用国内云服务器(如阿里云、腾讯云)拉取
- 用
autodl等平台的稳定网络环境
✅ 三、验证是否修复
git clone https://ghproxy.com/https://github.com/youngyangyang04/Test-Automation-Framework.git
如果能正常下载,说明成功!
✅ 四、总结:推荐操作顺序
1️⃣ |
(关闭 HTTP/2) |
2️⃣ | 再次
|
3️⃣ | 如果还不行 → 改用 SSH 克隆 |
4️⃣ | 仍失败 → 用
加速 |
5️⃣ | 最后尝试换网络 |
💡 小贴士
ghproxy.com临时加速,适合一次性下载。- SSH 长期稳定,建议配置一次。
http.version = HTTP/1.1是最简单有效的解决方案!
✅ 一句话总结:
❌ 错误
HTTP/2 stream 1 was not closed cleanly是网络或协议问题,✅ 用
git config --global http.version HTTP/1.1关闭 HTTP/2,或改用 SSH/代理即可解决!
需要我帮你写一个一键修复脚本吗?或者生成 SSH Key 的完整流程?欢迎继续问 😊