惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

腾讯CDC
aimingoo的专栏
aimingoo的专栏
S
SegmentFault 最新的问题
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
WordPress大学
WordPress大学
N
Netflix TechBlog - Medium
MyScale Blog
MyScale Blog
Stack Overflow Blog
Stack Overflow Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - 聂微东
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Blog — PlanetScale
Blog — PlanetScale
T
Tailwind CSS Blog
Recent Announcements
Recent Announcements
Jina AI
Jina AI
大猫的无限游戏
大猫的无限游戏
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks

又见苍岚

COLMAP PatchMatch Stereo 算法详解 事件驱动的状态机框架:从理论到工程实践 分段五次多项式插值原理详解 路径插值方法深度对比研究 Claude Code 使用指南 OpenClaw 记忆管理与技能创建指南 CBS(Conflict-Based Search)算法详解 A* 算法及其变种详解 OpenClaw 配置多 Agents Windows Powershell 无法加载文件,因为在此系统上禁止运行脚本问题的解决方案 MaxClaw 安装流程 大模型 AI 名词介绍 AList 网盘聚合工具简介 Protobuf 简介与测试 Claude Code 简介以及 GLM 4.7 模型接入 Github 歌词下载工具 163MusicLyrics Python __getattr__ 懒加载 Python TypedDict 机器人仿真平台 Gazebo 安装记录 机器人仿真平台 Gazebo 简介 多机器人路径规划问题(Multi-Agent Path Finding, MAPF)简介 Python exifread 读取修改过的 jpeg 信息错误问题修复 3D 坐标系变换的理解 3D 旋转矩阵基本概念 MongoDB Compass 介绍 Python 环境管理工具 uv Flutter 开发指南 Snipaste 安装下载与黑屏问题解决方案 全局路径规划算法记录 2025 Python 版本性能测试
Git 在国内网络环境下无法 Push 的排查与修复 —— 配置 Clash ...
Yiwei Zhang · 2026-04-17 · via 又见苍岚

在国内服务器上开发时,git push 突然超时,SSH/HTTPS 全部连不上 GitHub。本文记录从诊断到修复的完整过程,核心原因是本地有 Clash 代理但 Git 和 SSH 没有配置使用它。

问题现象

git push 卡住直到超时:

1
2
3
$ git push origin main
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

逐步排查

1. 确认 Remote 和分支状态

1
2
3
4
5
6
$ git remote -v
origin git@github.com:xxx/xxx.git (fetch)
origin git@github.com:xxx/xxx.git (push)

$ git branch -vv
* main fac17aa [origin/main: ahead 50] feat: ...

远程地址是 SSH 协议,本地 ahead 50 个 commit,需要 push。

2. 测试 SSH 连接

1
2
$ ssh -T git@github.com -o ConnectTimeout=10
ssh: connect to host github.com port 22: Connection timed out

SSH 端口 22 超时。尝试 443 端口(参考前文):

1
2
$ ssh -T -p 443 git@ssh.github.com -o ConnectTimeout=10
ssh: connect to host ssh.github.com port 443: Connection timed out

443 也超时,说明不是简单的端口封禁问题。

3. 测试 HTTPS 和 Ping

1
2
3
4
5
$ curl -s --connect-timeout 10 -o /dev/null -w "HTTP %{http_code} in %{time_total}s\n" https://github.com
HTTP 000 in 10.002881s

$ ping -c 2 -W 3 github.com
2 packets transmitted, 0 received, 100% packet loss

GitHub 完全不可达。国内网络验证正常:

1
2
$ curl -s --connect-timeout 10 -o /dev/null -w "HTTP %{http_code} in %{time_total}s\n" https://www.baidu.com
HTTP 200 in 0.234748s

结论:GitHub 被网络环境完全阻断。

4. 寻找本地代理

1
2
$ ss -tlnp | grep -E ':(1080|7890|7891|10808|10809)'
LISTEN 0 4096 127.0.0.1:7890 0.0.0.0:* users:(("clash-linux",pid=7459,fd=10))

Clash 在 127.0.0.1:7890 运行。验证代理能否访问 GitHub:

1
2
$ curl -s --connect-timeout 5 -x http://127.0.0.1:7890 -o /dev/null -w "HTTP %{http_code} in %{time_total}s\n" https://github.com
HTTP 200 in 3.519280s

HTTP 代理可用。

修复方案

需要配置两层代理:Git HTTPS 代理 + SSH over 代理。

1. 配置 Git HTTP/HTTPS 代理

适用于 HTTPS 协议的 remote(https://github.com/...):

1
2
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

2. 配置 SSH 走代理

当前 remote 是 SSH 协议(git@github.com:...),SSH 不走 http.proxy,需要额外配置。

编辑 ~/.ssh/config,在文件顶部添加:

1
2
3
4
Host github.com
HostName github.com
User git
ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=7890

注意:需要系统安装 socat。如果没有可以用 nc(netcat)替代:

1
ProxyCommand nc -X connect -x 127.0.0.1:7890 %h %p

如果都没有,Ubuntu 上安装:sudo apt install socat

3. 验证与推送

1
2
3
4
5
6
$ ssh -T git@github.com -o ConnectTimeout=15
Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.

$ git push origin main
To github.com:xxx/xxx.git
7687894..fac17aa main -> main

推送成功。

补充说明

  • 取消代理:如果之后网络环境变化不需要代理了,清除配置:
1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

然后删除 ~/.ssh/config 中的 Host github.com 块即可。

  • 仅对 GitHub 生效:上述 SSH 配置仅对 github.com 域名生效,不影响其他 SSH 连接。

  • SOCKS5 vs HTTP:经测试当前 Clash 的 SOCKS5 端口不可用(socks5://127.0.0.1:7890 超时),只有 HTTP 代理端口可用,实际使用时需确认自己代理工具的有效端口和协议。

参考资料

文章链接:
https://www.zywvvd.com/notes/tools/git/git-proxy-clash/git-proxy-clash/