背景:
剛才在使用github時,發現直接下載zip的時候,速度非常快,但是使用git clone時發現速度只有15kb/s左右。這一定是不合理。
想着使用梯子,下載速度一定會有所提升,結果發現速度直接使用全局代理是不能有幫助。
所以花了一些時間研究了以下。
預備知識:
首先,git clone有兩個種,一種是基於http的(暫把其代號設為A,便於后續分類討論),另一種是基於ssh的(暫把其代號設為B,便於后續分類討論)。
使用形式分別為:
git clone https://github.com/stevenlovegrove/Pangolin.git
gti clone git@github.com:stevenlovegrove/Pangolin.git
另外,基於shadowsocks的代理,也是有兩種方法的,一種是http(暫把其代號設為1,便於后續分類討論),另一只是socks5(暫把其代號設為2,便於后續分類討論)的。
如下圖我的協議就是socks5的。

好的,一切准備就緒,因為現在有兩種git協議(A,B),兩種代理協議(1,2),所以有四種設置方法。
A1:基於http的git與基於http的代理
好的,一切准備就緒,因為現在有兩種git協議(A,B),兩種代理協議(1,2),所以有四種設置方法。
git config --global http.proxy "http://127.0.0.1:1080"
git config --global https.proxy "http://127.0.0.1:1080"
A2:基於http的git與基於socks5的代理
git config --global http.proxy "socks5://127.0.0.1:1080" git config --global https.proxy "socks5://127.0.0.1:1080"
B1:基於ssh的git與基於http的代理
修改~/.ssh/config文件,如在ubuntu下使用: gedit ~/.ssh/config
添加如下內容:
Host github.com
HostName github.com
User git
ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=1080
添加完畢,記得保存
B2:基於ssh的git與基於socks5的代理
修改~/.ssh/config文件,如在ubuntu下使用: gedit ~/.ssh/config
添加如下內容:
Host github.com
HostName github.com
User git
ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
添加完畢,記得保存
結果對比

Enjoy~
