完整解決git clone在國內網速過慢的問題,無論是https還是ssh都可以流暢clone倉庫項目到本地
本方案操作系統為 mac osx10.14.5,如需windows解決方案可參考本文并結合參考資料中的內容進行調整
效果圖
HTTPS 下載速度
image-20210107205116362.png
SSH下載速度
image-20210107204837559.png
解決方案
三個方法可以同時使用
方法一:配置github全局代理
該方法僅適用于通過
https
形式clone倉庫
首先你需要安裝ss代理
-
打開ss偏好設置,查詢到http監聽端口號
image-20210107205214542.png -
配置git config
git config --global http.proxy http://127.0.0.1:1087 git config --global https.proxy https://127.0.0.1:1087
步驟三配置后,可以測試git clone 速度,如果已經加速表示成功,但是該方法將導致國內倉庫無法下載,建議改成以下形式
git config --global http.https://github.com.proxy.proxy http://127.0.0.1:1087
git config --global https.https://github.com.proxy https://127.0.0.1:1087
方法二:修改本地host文件
由于國內環境github的cdn不穩定導致解析失敗,所以我們可以在本地host中直接指定
打開 IPAddress.com分別查詢
github.com
和github.global-ssl.fastly.net
兩個域名的ip地址本地編輯host文件
sudo vim /etc/hosts
-
sudo vim /etc/hosts
199.232.69.194 github.global-ssl.fastly.net 140.82.114.4 github.com
方法三:解決ssh加速
-
打開ss首選項找到
Sock監聽端口
image-20210107203519842.png -
vim ~/.ssh/config
Host github.com User git ProxyCommand /usr/bin/nc -x 127.0.0.1:1080 %h %p IdentityFile ~/.ssh/id_rsa # 這里是github上的ssh對應私鑰
windows系統也是類似的配置可以看參考資料[1]中有相關方案