一、为什么 GitHub 这么慢?(先搞懂原理)
1.1 网络延迟的罪魁祸首
GitHub 服务器主要部署在北美地区,国内访问需要经过多个国际网络节点。根据实际测试(使用 tracert 命令),北京到 GitHub 的请求可能经过多个路由节点。
1.2 DNS 污染问题
某些地区的 DNS 解析会被劫持,导致无法正确解析 github.com 的 IP 地址。可以使用以下命令检查:
nslookup github.com
如果返回的 IP 不是官方地址(如 20.205.243.166),说明 DNS 可能被污染。
二、5 大加速方案实测对比(附详细步骤)
2.1 镜像站大法(新手首选)
国内维护的镜像站实测速度较快。常用镜像地址:
使用技巧:直接把 github.com 替换成镜像域名即可。比如原地址:
git clone https://github.com/vuejs/vue.git
替换后:
git clone https://hub.yzuu.cf/vuejs/vue.git
2.2 修改 Hosts 文件(永久生效)
- 查询以下域名的 IP:
- github.com
- assets-cdn.github.com
- github.global.ssl.fastly.net
- 编辑 hosts 文件(路径:C:\Windows\System32\drivers\etc\hosts)
- 添加记录(示例):
20.205.243.166 github.com
185.199.108.153 assets-cdn.github.com
199.232.69.194 github.global.ssl.fastly.net
2.3 Git 配置代理(程序员必备)
如果你有代理工具,可以设置 git 代理:
# Socks5 代理
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080
# HTTP 代理
git config --global http.proxy http://127.0.0.1:1080
git config --global https.proxy https://127.0.0.1:1080
2.4 使用 Gitee 中转(适合大项目)
- 在 Gitee 导入 GitHub 仓库
- 从 Gitee 克隆仓库
- 修改 remote 地址指向原始 GitHub 仓库:
git remote set-url origin https://github.com/原仓库地址.git


