GitHub 项目国内镜像获取指南
一句话
GitHub 直连不稳定是国内开发者的头号痛点。这篇教程汇总了 5 种镜像方案,无论你的网络环境如何,总有一个能跑通。
🤖 AI Agent 快速入口
curl -H "Accept: text/markdown" https://doc.k4b.cn/deployment/github-mirror-guide.md
方案对比
| 方案 | 速度 | 稳定性 | 适用场景 |
|---|---|---|---|
| ghproxy.com | ⭐⭐⭐ | ⭐⭐⭐⭐ | 日常 clone,最推荐 |
| Git 代理 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 你已经有代理时 |
| gitclone.com | ⭐⭐⭐ | ⭐⭐⭐ | ghproxy 备选 |
| Gitee 导入 | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ | 需要长期维护的项目 |
| 手动下载 ZIP | ⭐⭐ | ⭐⭐⭐⭐⭐ | 无需 git 历史的场景 |
⚠️ 镜像服务免责声明:镜像站(如 ghproxy)是第三方服务,可能加速也可能失效,请按需选用。本站不托管任何 GitHub 源码,只提供镜像获取的方案说明。如果你使用镜像站下载了代码,建议拿到后验证文件完整性。
方案一(推荐):ghproxy.com 代理
最简单、最稳定的方案。只需要在 clone 的 URL 前加上 https://ghproxy.com/:
# 原始 URL
git clone https://github.com/user/repo.git
# 加 ghproxy(推荐)
git clone https://ghproxy.com/https://github.com/user/repo.git
# 下载 release 文件同样适用
wget https://ghproxy.com/https://github.com/user/repo/releases/download/v1.0.0/file.zip优点
- 无需安装任何东西
- 直接在 git clone 命令里改就行
- 支持下载 release 文件
缺点
- 偶尔会超时,重试一次就好
- 大文件(>100MB)可能不稳定
方案二:Git 代理
如果你已经有代理工具(Clash/V2Ray),直接让 Git 走代理更高效:
# 设置代理(假设代理在 7890 端口)
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 然后正常 clone
git clone https://github.com/user/repo.git
# 用完取消代理
git config --global --unset http.proxy
git config --global --unset https.proxy只针对 GitHub 设置代理(推荐)
# 只给 github.com 走 ghproxy 镜像加速
git config --global url."https://ghproxy.com/".insteadOf https://github.com/💡 如果你用 SOCKS5 代理:
bashgit config --global http.proxy socks5://127.0.0.1:7890
方案三:gitclone.com
ghproxy 的备选,用法完全一样:
git clone https://gitclone.com/github.com/user/repo.git方案四:Gitee 导入
适合需要长期稳定维护的 GitHub 项目。把 GitHub 仓库同步到 Gitee(码云),国内速度拉满。
手动方式:
- 打开 gitee.com
- 点击右上角 "+" → "从 GitHub/GitLab 导入仓库"
- 粘贴 GitHub 仓库地址
- 点击 "导入"
自动同步(保持仓库更新):
- Gitee 仓库 → "管理" → "仓库镜像管理" → "添加镜像"
- 填入 GitHub 仓库地址
- Gitee 会定期自动同步
# 导入后,从 Gitee clone
git clone https://gitee.com/yourname/repo.git方案五:手动下载 ZIP
如果你只需要代码、不需要 git 历史(不上传不修改),直接下载 ZIP:
# 通过 ghproxy 下载
wget https://ghproxy.com/https://github.com/user/repo/archive/refs/heads/main.zip
unzip main.zip或者在浏览器打开 GitHub 仓库页面,点 "Code" → "Download ZIP"。
常见问题
Q:所有镜像都失效了怎么办? A:没有一个镜像能 100% 永久可用。建议每隔一段时间关注 GitHub 上最新的镜像推荐。目前 ghproxy.com 是维护比较活跃的,如果发现失效,方案二(自己的代理)是最稳定的长期方案。
Q:我该优先用哪个方案? A:先试 ghproxy.com(方案一),不行就 Git 代理(方案二),再不行就换 gitclone.com(方案三)。如果是需要频繁访问的仓库,走 Gitee 导入(方案四)。
Q:镜像方案会不会有安全风险? A:镜像站通过中转你的请求来下载代码,理论上镜像站能看到你下载了什么仓库。但大多数情况下它们不解析文件内容。不放心的话,用方案二(自己的代理)最安全。
相关教程
- OpenClaw 国内安装与配置 — 综合运用镜像方案
- Docker 部署 AI Agent(镜像加速版) — Docker 镜像也有类似的加速方案
- AI Agent 部署十大常见坑 — 镜像问题只是其中之一