Git用shadowsocks加速
用shadowsocks加速git clone
利用shadowsocks的socks5代理,配置好后明顯加速坡贺。用下面兩條命令配置好后壁肋,保持shadowsocks客戶端開啟就行了沃斤。
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
shadowsocks的本地端口默認(rèn)是1080
上面設(shè)置只是開啟https://代理
git開啟http/https代理詳解
# 查看git 可以配置的內(nèi)容
git config
# 部分配置內(nèi)容詳解
global 即是讀/寫當(dāng)前用戶全局的配置文件(~/.gitconfig 文件,屬于某個計算機(jī)用戶)
system 即是讀寫系統(tǒng)全局的配置文件(/etc/gitconfig 文件,屬于計算機(jī))
local 即是當(dāng)前 clone 倉庫 的配置文件(位于 clone倉庫下 .git/config)拆祈。
blob 配置是另外一種形式,提供一個 blob 大對象格式倘感,沒有驗(yàn)證過放坏,估計與 local 是一樣的,只是形式不同老玛。
# 查看當(dāng)前代理設(shè)置
git config --global http.proxy
git config --global https.proxy
# 設(shè)置當(dāng)前代理為 http://127.0.0.1:1080 或 socket5://127.0.0.1:1080
git config --global http.proxy 'http://127.0.0.1:1080'
git config --global https.proxy 'https://127.0.0.1:1080'
git config --global http.proxy 'socks5://127.0.0.1:1080'
git config --global https.proxy 'socks5://127.0.0.1:1080'
# 刪除 proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
設(shè)置 Git SSH 代理(暫不可用)
還有一種情況淤年,我們通過 SSH 方法 clone 代碼,提交代碼蜡豹,因?yàn)檫@樣不用輸入密碼麸粮,通常我們會在自己的常用電腦上這么做。上面設(shè)置的 HTTP 代理對這種方式 clone 代碼是沒有影響的镜廉,也就是并不會加速弄诲,SSH 的代理需要單獨(dú)設(shè)置,其實(shí)這個跟 Git 的關(guān)系已經(jīng)不是很大娇唯,我們需要改的齐遵,是SSH 的配置寂玲。在用戶目錄下建立如下文件 ~/.ssh/config,對 GitHub 的域名做單獨(dú)的處理
# 這里必須是 github.com梗摇,因?yàn)檫@個跟我們 clone 代碼時的鏈接有關(guān)
Host github.com
# 如果用默認(rèn)端口拓哟,這里是 github.com,如果想用443端口留美,這里就是 ssh.github.com 詳見 https://help.github.com/articles/using-ssh-over-the-https-port/
HostName github.com
User git
# 如果是 HTTP 代理彰檬,把下面這行取消注釋,并把 proxyport 改成自己的 http 代理的端口
# ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=6667
# 如果是 socks5 代理谎砾,則把下面這行取消注釋逢倍,并把 6666 改成自己 socks5 代理的端口
# ProxyCommand nc -v -x 127.0.0.1:6666 %h %p
git開啟ssh代理詳解
git使用ssh代理要借助第三方工具,比如:nc,通過修改ssh配置文件同時將整個系統(tǒng)的ssh連接走代理
nc 這個工具一般的Ubuntu系統(tǒng)都帶的有.沒有的話apt insttall nc
,Mac使用brew install nc
- 添加代理
# ServerAliveInterval定時向服務(wù)器發(fā)送消息以保持連接,防止不操作而斷開.需要的時候才添加
echo "ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p" >> ~/.ssh/config
echo "ServerAliveInterval 30" >> ~/.ssh/config
- 取消代理
# Linux直接修改源文件
sed -i '/ProxyCommand/d' ~/.ssh/config
# Mac下只能這么弄,否則提示參數(shù)錯誤
sed '/ProxyCommand/d' ~/.ssh/config > ~/.ssh/config.bk && mv ~/.ssh/config.bk ~/.ssh/config
# 或者
sed '/ProxyCommand/d;/ServerAliveInterval/d' ~/.ssh/config > ~/.ssh/config.bk && mv ~/.ssh/config.bk ~/.ssh/config