GitHub 上面 clone 项目慢解决方法

树叶云

应该是很多小伙伴碰到过的问题:想从 GitHub 上面 clone 项目,很多情况下会慢的离谱,等待好久后报错,本篇文章重点为大家讲解一下解决git clone慢问题具体方法。

原因:git clone特别慢是因为github.global.ssl.fastly.net域名被限制了。只要找到这个域名对应的ip地址,然后在hosts文件中加上ip–>域名的映射,刷新DNS缓存便可。

适用各种操作系统,本次测试系统为Ubuntu 18.04.2 LTS,下载速度从几k提高到1M多。

没有修改前git clone速度实在慢只有10K左右,如上图。

修改后,git clone速度达到800多k。或者1M多。

1、查找域名对应的ip地址,并修改hosts文件

linuxidc@linuxidc:~/linuxidc.com$ nslookup github.global.ssl.fastly.Net
Server:  127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: github.global.ssl.fastly.Net
Address: 151.101.229.194
linuxidc@linuxidc:~/linuxidc.com$ nslookup github.com
Server:  127.0.0.53
Address: 127.0.0.53#53
Non-authoritative answer:
Name: github.com
Address: 13.229.188.59

如下图:

然后修改hosts文件

Windows上的hosts文件路径在

C:\Windows\System32\drivers\etc\hosts

Linux的hosts文件路径在/etc/hosts中

sudo vim /etc/hosts

Mac的hosts文件路径也在/etc/hosts中

sudo vi /etc/hosts

在hosts文件末尾添加两行

github.com 13.229.188.59
github.global.ssl.fastly.Net 151.101.229.194

2、刷新DNS缓存

Linux:

sudo /etc/init.d/networking restart

Windows:

ipconfig /flushdns

Mac:

sudo killall -HUP mDNSResponder

文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/210016.html<

(0)
运维的头像运维
上一篇2025-04-09 17:56
下一篇 2025-04-09 17:58

相关推荐

发表回复

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