爲 git bash 設置代理

由於直連通道的 clone, pull, push 等操作都很慢,我們需要爲其設置代理,以加快連接 github.com 的速度

本文操作環境是 Windows


HTTPS

目前來看,設置代理後加速最明顯的是 HTTPS, 爲其設置代理的方式如下

打開 git bash,然後輸入

git config --global http.proxy "http://127.0.0.1:1080"
git config --global https.proxy "https://127.0.0.1:1080"

這樣設置之後,git clone https://github.com/username/repo.git 的速度基本能跑滿帶寬

但是,這種方式並不適用於 git clone [email protected]:username/repo.git (ssh方式通信)


SSH

目前來看,https 方式速度較快,但是它有一個缺點,就是 git push 的時候需要輸入賬號密碼。因此我們最好也設置一下 ssh 通道的代理,說不定某些區域速度會比較快

打開 git bash 所在目錄的 .\etc\ssh,新建文件 config,注意沒有後綴名。添加以下內容

Host github.com
   User git
   IdentityFile "C:\Users\your-username\.ssh\id_rsa"
   ProxyCommand connect.exe -H 127.0.0.1:1080 %h %p

其中有一個代理連接軟件 connect.exe 可以從這裏尋找下載地址。


其他

除了設置代理,我們還可以設置 hosts

192.30.253.112    github.com
192.30.253.113    github.com
151.101.185.194   github.global.ssl.fastly.net

爲了找到這倆域名的 IP,我們可以訪問 https://ipaddress.com/


參考資料

https://imciel.com/2016/06/28...

https://stackoverflow.com/que...

https://help.github.com/en/ar...

https://www.liaoxuefeng.com/w...

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章