GitHub 服务器位于海外,受 DNS 污染、国际线路拥堵等因素影响,国内访问经常遇到以下问题:

  • 网页打开缓慢、频繁超时
  • git clone 速度极慢或直接失败
  • Release 大文件下载中断

下面整理了 3 种实测有效的解决方法,按推荐程度排序。

GitHub 访问加速

方法一:URL 前缀代理

原理:在原始 GitHub 地址前拼接一个加速域名,请求先经国内加速节点转发。

# 站点 类型 支持范围 速度 上手难度
1 gh-proxy.com URL 前缀代理 clone + Release + raw + archive ★★★★
2 ghfast.top URL 前缀代理 clone + Release + raw ★★★★
3 mirror.ghproxy.com URL 前缀代理 clone + Release + raw ★★★
4 hub.gitmirror.com URL 前缀代理 clone + Release ★★★

安全提示:以上均为第三方加速服务,请求会经过对方服务器。请仅用于公开仓库,不要用它克隆私有仓库,也不要在使用期间执行需要凭据的 git push

gh-proxy.com

1
2
3
4
5
6
7
8
# 单文件下载
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

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

备用域名集合站:https://ghproxy.link/,主域名失效时可自动切换可用镜像。

mirror.ghproxy.com

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

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

hub.gitmirror.com

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

适合国内服务器拉取镜像。

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

每次手动加前缀比较麻烦,可以用 Git 的 insteadOf 自动把 GitHub 地址重写为镜像地址。以下方案任选其一即可,不要同时配置

1
2
3
4
5
6
7
8
# 方案 A:gh-proxy.com
git config --global url."https://gh-proxy.com/https://github.com/".insteadOf "https://github.com/"

# 方案 B:hub.gitmirror.com
git config --global url."https://hub.gitmirror.com/https://github.com/".insteadOf "https://github.com/"

# 方案 C:gitclone.com(仅支持 clone)
git config --global url."https://gitclone.com/github.com/".insteadOf "https://github.com/"

这样只匹配 https://github.com/ 开头的地址,不会影响 GitLab、Gitee 等其他站点

如果只想在特定目录生效,可以用 includeIf 按目录隔离:

1
2
3
4
5
6
7
# ~/.gitconfig
[includeIf "gitdir:~/work/"]
path = ~/.gitconfig-work

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

注意:早期教程常用 insteadOf "https://",它会接管所有 HTTPS 地址,可能影响非 GitHub 仓库并向第三方泄露凭据,不建议使用。

gitclone.com(仅 clone 场景)

1
git clone https://gitclone.com/github.com/owner/repo.git

注意路径格式是 gitclone.com/github.com/,而不是 gitclone.com/https://github.com/

方法二:修改 hosts(DNS 指定)

原理:把 github.comraw.githubusercontent.com 等域名直接绑定到可用 IP,绕过被污染的 DNS 解析。

GitHub520

macOS / Linux 一次性更新:

1
2
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 不会参与。

方法三:Watt Toolkit(原 Steam++)

图形化工具,开箱即用,官网:https://steampp.net/

除 GitHub 外,还能一键加速 Steam 商店等,适合不想折腾命令行的用户。

总结

场景 推荐方案
临时下载 / 克隆 方法一:URL 前缀代理
全局生效、免手动加前缀 url.insteadOf 配置
仅需 clone gitclone.com
图形化操作 方法三:Watt Toolkit
网页 / git / 下载整体提速 方法二:hosts(GitHub520)