九章智算云

GitHub 国内加速访问

国内拉 GitHub 经常超时或被中断,影响:

  • 拉训练框架(vLLM / SGLang / llama.cpp / DeepSpeed / LLaMA-Factory …)
  • 下载 release artifact(模型权重、wheel 包、二进制工具)
  • pip / npm 依赖里带的 git+https://github.com/...
  • HuggingFace 工具链里走 GitHub 的部分(transformers 源码安装、peft 仓库等)

本页给出几条「在 pod 内把 GitHub 拉得动」的常用方法。

本页列出的镜像站均为社区公益代理,不是 GitHub 官方服务。镜像可能随时调整域名或下线,使用前先 curl -I 探测一下连通性,并不要把私仓 clone 或带 token 的请求走第三方代理(凭据可能泄漏)。

公益加速镜像

下面几个国内可用,挑一个能连通的即可。如果一个挂了,换下一个。

镜像地址形式
GH-Proxyhttps://ghproxy.comhttps://ghproxy.netURL 前缀代理
Akamshttps://github.akams.cn网页输入框下载
LLKKhttps://gh.llkk.ccURL 前缀代理
GitMirrorhttps://hub.gitmirror.comURL 前缀代理

「URL 前缀代理」的用法是把 https://github.com/... 换成 https://<镜像>/https://github.com/...,所有命令行工具都吃这一套。

终端用法

下面以 https://ghproxy.com 为例,换成其他「URL 前缀代理」用法相同。

git clone

git clone https://ghproxy.com/https://github.com/vllm-project/vllm

wget 下载 release

wget https://ghproxy.com/https://github.com/microsoft/vscode/archive/refs/tags/1.82.3.zip

curl 下载 release

curl -LO https://ghproxy.com/https://github.com/github/gh-ost/releases/download/v1.1.6/gh-ost

下载 raw 文件

curl https://ghproxy.com/https://raw.githubusercontent.com/microsoft/vscode/main/LICENSE.txt

支持的 URL 形式:

  • Raw 文件:https://raw.githubusercontent.com/<owner>/<repo>/<branch>/<file>
  • 分支源码:https://github.com/<owner>/<repo>/archive/refs/heads/<branch>.zip
  • Releases 文件:https://github.com/<owner>/<repo>/releases/download/<tag>/<file>
  • Releases 源码:https://github.com/<owner>/<repo>/archive/refs/tags/<tag>.zip

不支持整个项目文件夹的离线打包下载 —— 那种用 git clone 拉源码再压缩。

让所有 git 命令走加速(永久)

git configgithub.com 全局重写成代理 URL,之后所有 git clone / git submodule update 都自动走加速:

# 全局开启
git config --global url."https://ghproxy.com/https://github.com/".insteadOf "https://github.com/"

# 卸载
git config --global --unset url."https://ghproxy.com/https://github.com/".insteadOf

insteadOf 是 git 内置功能,只对匿名 clone(HTTPS 公开仓库)生效。SSH(git@github.com:...)和带凭据的私仓不走这条规则,不会有泄漏风险。

pip install git+ 走加速

很多 Python 库的安装命令是 pip install git+https://github.com/...,如果开了上面 git config 全局,pip 会自动走代理,不用改命令。

如果只想临时用一次:

pip install git+https://ghproxy.com/https://github.com/huggingface/peft

在 Dockerfile 中预置加速

镜像构建时拉 GitHub 是高频痛点,可以把 git config 写进 Dockerfile,只在构建期生效:

RUN git config --global url."https://ghproxy.com/https://github.com/".insteadOf "https://github.com/" \
 && git clone https://github.com/vllm-project/vllm.git \
 && git config --global --unset url."https://ghproxy.com/https://github.com/".insteadOf

构建后镜像跑起来时不带这条配置,生产容器里 git 走原始 GitHub。

配合 HuggingFace 镜像一起用

如果同时拉 GitHub 源码 + 下 HF 模型权重,记得两条加速分别开:

两套独立,互不影响。

镜像挂了怎么办

公益代理没有 SLA,流量大的时候抽风很常见。

判断顺序:

# 1. 看 GitHub 直连是不是真的不行(国内有时候是通的)
curl -I --max-time 10 https://github.com

# 2. 探测代理连通
curl -I --max-time 10 https://ghproxy.com
curl -I --max-time 10 https://gh.llkk.cc
curl -I --max-time 10 https://hub.gitmirror.com

哪个返回 200/30x 就用哪个,在 git config 里改一下 URL 即可。

如果所有公益代理都挂了,临时方案:

  • 在自己的境外机器(海外 VPS / 自建 IDC)搭 gh-proxy 自用
  • 把仓库 fork 到 Gitee,临时 git clone https://gitee.com/<your>/<repo>
  • huggingface-cli download 走 HF 镜像下模型权重(不走 GitHub)

注意事项汇总

  • 第三方代理是社区公益项目,不要走私仓或带 token 的请求(凭据可能被记录)
  • 走代理只对公开仓库安全
  • 镜像域名不稳定,写脚本时不要 hardcode,优先用 git config insteadOf 集中切换
  • 镜像速度跟时段强相关,白天 / 周末经常更慢
  • SSH(git@github.com:)走的是端口 22,代理一般不接 SSH,要走 SSH 自己挂 Shadowsocks / Clash

最后更新于

这篇文档对你有帮助吗?

目录