一篇文章完美解决国内无法访问github、github文件下载慢问题

内容纲要

~~ 方法一 使用国内映射站(已失效)~~

~~镜像网站(可以访问网页,可以用来clone push,和直接使用github体验相同)
https://hub.fastgit.xyz 可浏览器直接访问,此站备用域名:https://hub.fastgit.org~~

使用命令行clone工程时慢的解决方法(已失效)

~~ 原始clone命令: ~~

 git clone https://github.com/tensorflow/tensorflow.git

替换后的clone命令:

 git clone https://hub.fastgit.xyz/tensorflow/tensorflow.git

下载github文件慢的解决方法(已失效)

~~ 对请求url做替换即可(将github.com替换为download.fastgit.org),示例如下:
github原始下载地址:~~

https://github.com/btnkij/qsv2flv/releases/download/beta-test/qsv2flv-beta-x64.exe

替换后的地址:

https://download.fastgit.org/btnkij/qsv2flv/releases/download/beta-test/qsv2flv-beta-x64.exe

方法一:GitHub 文件加速

利用 Cloudflare Workers 对 github release 、archive 以及项目文件进行加速,部署无需服务器且自带CDN.

演示站点(如无法打开可自行部署:gh-proxy-GitHub(https://hunsh.net/archives/23/) ):
https://gh.api.99988866.xyz 使用方法如图中示例所示:
file
http://toolwa.com/github/
https://github.ur1.fun/
file
https://github.zhlh6.cn (可使用git clone)
file

谷歌浏览器 GitHub 加速插件(推荐)

file

GitHub raw 加速

下载GitHub raw资源的域名为(raw.githubusercontent.com)并非 github.com,因此上述的 GitHub加速可能无法加速这个域名,我们可以使用 Static CDN 提供的反代服务。

http://raw.githubusercontent.com 替换为 http://raw.staticdn.net 即可加速

资料来源网址:https://zhuanlan.zhihu.com/p/314071453

方法二 kx上网(购买或自己搭建梯子访问)

已经kx上网,git clone 速度还是慢的解决方法

分辨需要设置的代理

  • HTTP 形式:
    git clone https://github.com/owner/git.git

  • SSH 形式:
    git clone git@github.com:owner/git.git

第一种https形式解决方法

走 HTTP 代理

git config --global http.proxy "http://127.0.0.1:8080"
git config --global https.proxy "http://127.0.0.1:8080"

走 socks5 代理(如 Shadowsocks)

git config --global http.proxy "socks5://127.0.0.1:1080"
git config --global https.proxy "socks5://127.0.0.1:1080"

取消设置

git config --global --unset http.proxy
git config --global --unset https.proxy

第二种ssh形式解决方法

修改 ~/.ssh/config 文件(不存在则新建):

 # 必须是 github.com
Host github.com
   HostName github.com
   User git
   # 走 HTTP 代理
   # ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=8080
   # 走 socks5 代理(如 Shadowsocks)
   # ProxyCommand nc -v -x 127.0.0.1:1080 %h %p

方法三 使用gitee做中转

对经常访问的项目可以使用gitee的镜像功能将工程复制自己的repository

  • 登录gitee,头像旁边有+号
  • 点击+号,选择"从github或gitlab导入仓库"
    file
  • 导入完成后就可以使用gitee网址进行clone和push了

方法四 修改hosts文件或者dns

这种方式修改比较麻烦,并且很容易失效,解决的是网络波动的问题,就算可以访问,速度也不会很快,不推荐。优先使用上述三种方式
传送门

参考文章

开启 https & ssh 代理,让 git clone 快到飞起 https://juejin.cn/post/6847902220420120589
https://gist.github.com/chuyik/02d0d37a49edc162546441092efae6a1

一篇文章完美解决国内无法访问github、github文件下载慢问题

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

滚动到顶部