概括

如果是下载比较大的项目,比如耗时 5min 往上,大小 30mb 往上,十分推荐使用镜像网站,或者转入gitee的方式下载.

如果仅仅是下载比较小的项目,类似代码性质,文档性质的项目,使用cdn加速,提升到100多KB/s也就够用了

使用镜像网站

使用github的镜像网站

原地址:

https://github.com/xxx.git

替换为:

https://github.com.cnpmjs.org/xxx.git

示例:

git clone https://github.com.cnpmjs.org/xxx.git

说白了,就在 http://github.com 后面加个 .cnpmjs.org 即可

缺点: 每次访问页面都需要手动添加一次 .cnpmjs.org

对于 github release 中下载的大文件

使用 https://toolwa.com/github/来下载,速度起飞,无需注册,亲测有效。

cdn加速

通过修改系统 hosts 文件的办法,绕过国内dns解析,直接访问GitHub的CDN节点,从而达到github访问加速的目的。不需要海外的服务器辅助。

GitHub在国内访问速度慢的问题原因有很多,但最直接和最主要的原因是GitHub的分发加速网络的域名遭到dns污染,下载网站上任何东西的时候会下半天,有时还会失败需要从头再来,多失败了几次又因访问次数过多被做了ip限制,让人恼火

做到以上需要三步

  1. 获取GitHub官方CDN地址
  2. 修改系统Hosts文件
  3. 刷新系统DNS缓存

获取GitHub官方CDN地址

首先,打开https://www.ipaddress.com/

查询以下三个链接的DNS解析地址

  1. github.com
  2. assets-cdn.github.com
  3. github.global.ssl.fastly.net
    github访问加速,亲测有效_.net

修改系统Hosts文件

接着,打开系统hosts文件(需管理员权限)。
路径:C:\Windows\System32\drivers\etc

mac或者其他linux系统的话,是/etc下的hosts文件,需要切入到root用户修改

# Copyright (c) 1993-2009 Microsoft Corp. 
# 
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows. 
# 
# This file contains the mappings of IP addresses to host names. Each 
# entry should be kept on an individual line. The IP address should 
# be placed in the first column followed by the corresponding host name. 
# The IP address and the host name should be separated by at least one 
# space. 
# 
# Additionally, comments (such as these) may be inserted on individual 
# lines or following the machine name denoted by a '#' symbol. 
# 
# For example: 
# 
#      102.54.94.97     rhino.acme.com          # source server 
#       38.25.63.10     x.acme.com              # x client host 




# localhost name resolution is handled within DNS itself. 
#   127.0.0.1       localhost 
#   ::1             localhost 


140.82.112.3    github.com
185.199.108.153 assets-cdn.github.com
199.232.69.194  github.global.ssl.fastly.net

并在末尾添加三行记录并保存。(需管理员权限,注意IP地址与域名间需留有空格)

刷新系统DNS缓存

最后,Windows+X 打开系统命令行(管理员身份)或powershell

运行 ipconfig /flushdns 手动刷新系统DNS缓存。

mac系统修改完hosts文件,保存并退出就可以了.不要要多一步刷新操作.
centos系统执行/etc/init.d/network restart命令 使得hosts生效

github访问加速,亲测有效_github_02

转入gitee加速

最终下载速度对比

github 42KB/s (加了github访问cdn)
github访问加速,亲测有效_缓存_03
gitee 1034KB/s 大约25倍与github的速度
github访问加速,亲测有效_管理员权限_04
例:我们要下载

https:://github.com/DoubleLabyrinth/navicat-keygen

先访问要下载的仓库的地址(在chrome中打开)

点击fork (fork会把这个仓库复制一份到你的github账号的名下,所以你需要有个githu账号,没有的注册一下,有了的记得登陆)

点完之后
github访问加速,亲测有效_缓存_05
注意到这个仓库已经到了我们的名下

好了 github这边的事我们暂时做完了

现在登陆gitee (没有账号的注册一个账号)

然后点击
github访问加速,亲测有效_缓存_06
接着会出现一个授权
github访问加速,亲测有效_缓存_07
然后可能会出现第一输入密码的地方
github访问加速,亲测有效_git_08
这儿输入mac的登陆密码 并点击始终允许

然后出现
github访问加速,亲测有效_github_09
输入 github账号的密码 之后出现
github访问加速,亲测有效_管理员权限_10
选择我们刚刚的项目 navicat-keygen -> 导入

gitee正在帮我们从github下载(gitee从github下载的速度一定是很快的,毕竟大网站)
github访问加速,亲测有效_管理员权限_11

一般来说30s内就处理好自动刷新了
github访问加速,亲测有效_缓存_12

然后我们复制这个网址
github访问加速,亲测有效_git_13
然后我们下载这个地址

可以看到速度
github访问加速,亲测有效_github_14