Improve the Speed of Git Clone from Github

 Tools / Git
 

出现障碍

更新Vim到8.1后检查插件状态,发现ale需要重新安装。

用的插件管理器是Vim-Plug,在.vimrc.bundles中添加:

1
Plug 'w0rp/ale'

之后在Vim中执行命令

:PlugInstall

看着屏幕上的进度条一点点地跑到终点,终端却抛来如下错误:

1
2
3
4
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
fatal: The remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

分析原因

看上诉错误的字面意思是下载的包在传输过程中提前结束。我以为凑巧出错便重新下载。

经过实验多次,这样的错误发生不是偶然。之后,经过查阅文档,我发现Vim-Plug实际上采

用git来下载安装Github上的插件项目。然而,国内用终端克隆Github上Repository速度特慢,

猜测此次障碍可能由此造成。

解决办法

1. 为git设置代理

在设置了SS代理的前提下,从终端输入:

1
2
git config --global http.https://github.com.proxy socks5://127.0.0.1:1080
git config --global https.https://github.com.proxy socks5://127.0.0.1:1080

2. 修改Hosts

用以下命令查找github.global.ssl.fastly.Net和github.com对应的IP地址:

1
2
nslookup github.global.ssl.fastly.Net
nslookup github.com

之后将IP地址和域名对添加到/etc/hosts文件。

最终效果

git clone的速度从10.0KB/s提升到150.0KB/s;出现的插件下载安装障碍得到解决。


参考文章

git clone速度太慢解决方案

git clone一个github上的仓库,太慢…