Git 设置代理

我们在写代码时,很容易遇到如下:

1
2
D:\temp>ssh [email protected]
ssh: Could not resolve hostname github.com

故我们需要为ssh配置proxy来访问github等网站

Git SSH

  • Windows
    ~/.ssh/config
1
2
3
4
5
Host github.com
Hostname ssh.github.com
Port 443
User git
ProxyCommand "C:\Program Files\Git\mingw64\bin\connect.exe" -S 127.0.0.1:7899 %h %p
  • Linux
    ~/.ssh/config
1
2
3
4
5
Host github.com
Hostname ssh.github.com
Port 443
User git
ProxyCommand nc -v -x 127.0.0.1:7899 %h %p

Git HTTP(S)

1
2
3
4
5
6
[http "https://github.com"]
proxy = socks5://127.0.0.1:7
[https "https://github.com"]
proxy = socks5://127.0.0.1:7
[git "https://github.com"]
proxy = socks5://127.0.0.1:7