这几天克隆下载GitHub代码奇慢无比,网上搜索了一下解决方案有些不太完整,自己试验出了比较完整的解决方式:
1、在C:\Windows\System32\drivers\etc\hosts文件里追加以下内容(IP需要替换掉 windows下dos窗口ipconfig /flushdns),
以下几个域名一个都不要少,有些文章只写了一部分,我一开始就少了个github.com,结果速度就还是很慢。
# GitHub Start 140.82.114.4 github.com 192.30.255.119 gist.github.com 185.199.110.153 assets-cdn.github.com 151.101.228.133 raw.githubusercontent.com 151.101.228.133 gist.githubusercontent.com 151.101.228.133 cloud.githubusercontent.com 151.101.228.133 camo.githubusercontent.com 151.101.228.133 avatars0.githubusercontent.com 151.101.228.133 avatars1.githubusercontent.com 151.101.228.133 avatars2.githubusercontent.com 151.101.228.133 avatars3.githubusercontent.com 151.101.228.133 avatars4.githubusercontent.com 151.101.228.133 avatars5.githubusercontent.com 151.101.228.133 avatars6.githubusercontent.com 151.101.228.133 avatars7.githubusercontent.com 151.101.228.133 avatars8.githubusercontent.com 185.199.109.154 github.githubassets.com 151.101.109.194 github.global.ssl.fastly.net # GitHub End
亲测最主要的是gist.github.com和 github.global.ssl.fastly.net这两个域名映射的ip
2、IP替换方法,打开 http://tool.chinaz.com/dns ,查询域名IP映射,把以上5个域名挨个查询一下,找一个TTL值比较小的IP替换掉。注意替换前要把IP先Ping一下,确保是通的才替换,否则是无效的。
3、替换后克隆代码速度从原来的几K/s一下子上升到了10M/s,如果过一段时间速度慢下来了,就再替换一次就好了。