git clone 慢/超时:9 种 GitHub 加速方案对比 2026

fatal: unable to access 'https://github.com/...': Failed to connect — 国内开发者每天都在见的报错。本文给一份 2026 还能用的 9 种加速方案,实测速度、可用性、适用场景一表对比。

一、问题成因

GitHub 在国内卡的根因有三层:

  1. DNS 污染:github.com 的解析常被指向不可达 IP
  2. TCP 连接不稳:能解析,但 TLS 握手超时 / 中间链路丢包
  3. 大文件 CDN 拒绝:codeload.github.com / objects.githubusercontent.com 频繁 503

不同方案针对不同层:hosts 改 DNS、镜像改路径、代理改链路。

二、9 种方案速览

#方案类型覆盖范围速度配置复杂度
1gh-proxy.comURL 前缀代理clone + Release + raw + archive★★★★
2ghfast.topURL 前缀代理clone + Release + raw★★★★
3mirror.ghproxy.comURL 前缀代理clone + Release + raw★★★
4hub.gitmirror.comURL 前缀代理clone + Release★★★
5全局 url.insteadOfgit config所有 git 仓库克隆★★★★★
6gitclone.comURL 前缀代理clone★★
7GitHub520 hostshosts 改 DNS全部 github 资源★★★★
8dev-sidecar本地 HTTPS 代理全部 github 资源★★★★★★★
9FastGithub 油猴浏览器扩展网页 + 文件下载★★★

三、方案 1-3:URL 前缀代理(推荐新手)

gh-proxy.com

# 单文件下载
wget https://gh-proxy.com/https://github.com/owner/repo/releases/download/v1.0/file.tar.gz

# 克隆仓库
git clone https://gh-proxy.com/https://github.com/owner/repo.git

# raw 文件
wget https://gh-proxy.com/https://raw.githubusercontent.com/owner/repo/main/README.md

支持 Release / raw / archive / git clone 全场景。实测速度 10-50 MB/s(国内移动 / 联通 / 电信均测过,移动最快)。

ghfast.top

wget https://ghfast.top/https://github.com/neovim/neovim/releases/download/stable/nvim-linux-x86_64.tar.gz

备用域名集合站:https://ghproxy.link/ — 主域名挂了自动切换到当前可用。

mirror.ghproxy.com

git clone https://mirror.ghproxy.com/https://github.com/InternLM/InternLM.git

功能与 gh-proxy 一致,稳定性偶尔波动。

四、方案 4-6:更多前缀代理

hub.gitmirror.com

适合在国内服务器上拉镜像。

git clone https://hub.gitmirror.com/https://github.com/owner/repo.git

全局 url.insteadOf(一次配置永久生效)

git config --global url."https://gitclone.com/".insteadOf "https://"
git config --global url."https://hub.gitmirror.com/https://".insteadOf "https://"
# 现在所有 git clone https://github.com/... 自动走 gitclone.com

按目录隔离配置:

# ~/.gitconfig
[includeIf "gitdir:~/work/"]
  path = ~/.gitconfig-work
# ~/.gitconfig-work
[url "https://hub.gitmirror.com/https://"]
  insteadOf = https://

gitclone.com

单纯 clone 场景最简单:

git clone https://gitclone.com/github.com/owner/repo.git
# 注意:这里是 gitclone.com/github.com/,不是 gitclone.com/https://github.com/

五、方案 7-8:DNS 与本地代理

GitHub520 hosts

原理:把 github.com / raw.githubusercontent.com 等域名直接绑到能通的 IP。

# 一次性更新 hosts(macOS / Linux)
sudo curl -o /tmp/hosts https://raw.hellogithub.com/hosts
sudo cat /tmp/hosts >> /etc/hosts

Windows 用 SwitchHosts 订阅 https://raw.hellogithub.com/hosts。

注意:hosts 只对走直连的流量生效,挂了全局代理就被代理接管,这时 hosts 不参与解析。

dev-sidecar(开发者本地代理)

https://github.com/docmirror/dev-sidecar

开箱即用的本地 HTTPS 代理,默认覆盖 GitHub / Stack Overflow / Google 学术 等。安装后浏览器和 git 自动走代理,无需手动配。适合「我就要全局加速 GitHub 不想折腾」的人。

六、方案 9:浏览器场景

FastGithub 猴油脚本

https://github.com/RC1844/FastGithub — Tampermonkey / Violentmonkey 油猴脚本,自动在 GitHub 仓库页加「高速下载」按钮,搭配 IDM / NDM 多线程下载 200MB 以上文件极快。

七、按场景的推荐组合

场景推荐备注
日常 git clone 小仓库方案 5(全局 url.insteadOf)一次配置永久
偶尔下大 Release 文件方案 9(FastGithub 油猴)+ IDM多线程拉满
CI/CD 服务器方案 5 + 方案 4 备用多个镜像 fallback
开发机 Win/Mac方案 8(dev-sidecar)浏览器 + git 全覆盖
网页浏览 issues / 看 README方案 7(hosts)+ 方案 9不影响代理
私有仓库 / push 操作不要走第三方镜像,直接挂代理安全考虑

八、镜像方案 vs 走稳定代理

镜像免费但有三个固有缺陷:

  1. 流量大时被限速(尤其晚高峰)
  2. 私有仓 token 不能走(安全风险)
  3. 新域名 / 改路径不可控(运维方说了算)

如果你是日常重度 GitHub 用户(开发者 / 运维 / AI 工程师),长期更稳的方案是接一条兼容 Clash / Singbox / V2Ray 的订阅把 github.com 列为代理走,Release / Action Artifacts / raw / API 全部不卡。镜像方案当备路。

九、避坑提醒

  • 公益镜像随时可能改域名或停服,不要在生产环境的核心脚本里硬编码单个镜像域名 — 用变量或 fallback 列表
  • 国内云服务器(阿里云 / 腾讯云)拉 GitHub 不一定比家庭网快 — 部分机房禁出海带宽优化
  • Docker Hub 加速、npm 镜像、PyPI 镜像是另一套体系,本文不涵盖,见本站另文
  • git clone --depth=1 浅克隆能减少 70-90% 流量,小仓库够用

来源与时间戳

最后核对时间:2026-05-20。公益镜像域名可能随月变化,以 https://ghproxy.link/ 公示为准。