Ubuntu下git clone加速方法

Ubuntu下git clone加速方法

  • 环境 :Ubuntu 20 in Vmare
  • 问题:git clone复制github仓库时命令速度慢、无法访问
  • 解决:修改host文件

Step1 获取github IP地址

nslookup github.com

github.com
1
2
3
4
5
6
7
8
9
10
Server:         127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
Name: github.com
Address: 20.205.243.166
Name: github.com
Address: 2404:6800:4000::c01e:ff70
Name: github.com
Address: 2404:6800:4000::c01e:ff71```

Step2 获取github.global.ssl.fastly.net的IP地址

nslookup github.global.ssl.fastly.net

1
2
3
4
5
6
7
8
Server:         127.0.0.53
Address: 127.0.0.53#53

Non-authoritative answer:
Name: github.global.ssl.fastly.net
Address: 104.244.46.21
Name: github.global.ssl.fastly.net
Address: 2001::68f4:2e3f

Step3 访问host文件并修改

sudo vim /etc/hosts

在文件最后一行加上

1
2
3
4
5
6
7
#github
104.244.46.21 http://github.global.ssl.fastly.net
104.244.46.21 https://github.global.ssl.fastly.net

20.205.243.166 http://github.com
20.205.243.166 https://github.com

Step4 刷新缓存

sudo /etc/init.d/network-manager restart


即可解决github clone速度慢的问题

其他方法

1. 使用cgit工具

1
2
sudo apt-get install cgit
cgit clone ......

2. 添加gitclone.com前缀

例如:

git clone https://gitclone.com/github.com/tendermint/tendermint.git

可以设置git参数 实现自动替换

git config --global url."https://gitclone.com/".insteadOf https:


Ubuntu下git clone加速方法
https://thinler.github.io/2024/01/13/学习笔记/Ubuntu下git clone加速方法/
作者
Thinler
发布于
2024年1月13日
许可协议