git代理
参考: https://stackoverflow.com/questions/58245255/how-to-force-git-to-use-socks-proxy-over-its-ssh-connection
There are 2 types to clone git: HTTP, and ssh. There are 2 common types of proxy: HTTP, and socks. 克隆 Git 有两种方式:HTTP 和 ssh。有 2 种常见的代理:HTTP 和 socks。
Here’s the method dealing with 2 * 2 conditions:
# Method 1. git http + proxy http
git config --global http.proxy "http://127.0.0.1:1080"
git config --global https.proxy "http://127.0.0.1:1080"
# Method 2. git http + proxy shocks
git config --global http.proxy "socks5://127.0.0.1:1080"
git config --global https.proxy "socks5://127.0.0.1:1080"
# to unset
git config --global --unset http.proxy
git config --global --unset https.proxy
# Method 3. git ssh + proxy http
vim ~/.ssh/config
Host github.com
HostName github.com
User git
ProxyCommand socat - PROXY:127.0.0.1:%h:%p,proxyport=1087
# Method 4. git ssh + proxy socks
vim ~/.ssh/config
Host github.com
HostName github.com
User git
ProxyCommand nc -v -x 127.0.0.1:1080 %h %p
- I know this because it’s necessary for Chinese guys, hh. notion.so/… 我知道这一点,因为这对中国男人来说是必要的,所以……
- Use
Method 4
succeeded!- For method 3 & method 4, do NOT change the ‘Host github.com’ part or you will lose 10 mins to debug as I did. 对于方法 3 和方法 4,切勿更改 “Host github.com”部分,否则就会像我一样失去 10 分钟的调试时间。
- You can’t do metod 4 if your proxy requires authentication, but you can use
ncat
as follow:ProxyCommand ncat --proxy <proxy>:<port> --proxy-type socks5 --proxy-auth <user>:<pass> %h %p
如果代理需要身份验证,则无法使用元代码 4,但可以使用ncat
如下:ProxyCommand ncat --proxy <proxy>:<port> --proxy-type socks5 --proxy-auth <user>:<pass> %h %p
- for all windows platform guys. Use
ProxyCommand connect -S localhost:1081 %h %p
instead. 适用于所有 Windows 平台的用户。使用ProxyCommand connect -S localhost:1081 %h %p
代替。
发表回复