山高疑日近,海阔觉天低

Git代理

Git 目前支持的三种协议 gitsshhttp,其代理配置各不相同:

core.gitproxy 用于 git协议,

http.proxy 用于 http 协议,https.proxy 用于 https 协议,

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080

 

ssh协议的代理需要配置 ssh 的 ProxyCommand 参数。

Setting http.proxy will not work for ssh. You need to proxy your ssh connection. See thisdescription. To summarize:

Start git-cmd.bat and create ~/.ssh/config (notepad %home%\.ssh\config.)

ProxyCommand /bin/connect.exe -H proxy.server.name:3128 %h %p

Host github.com
  User git
  Port 22
  Hostname github.com
  IdentityFile "C:\users\username\.ssh\id_rsa"
  TCPKeepAlive yes
  IdentitiesOnly yes

Host ssh.github.com
  User git
  Port 443
  Hostname ssh.github.com
  IdentityFile "C:\users\username\.ssh\id_rsa"
  TCPKeepAlive yes
  IdentitiesOnly yes
Host VPS
HostName IP ADDR
Port *****
User git
ProxyCommand connect -S 10.0.0.249:1085 %h %p
IdentityFile ~/.ssh/id_rsa_VPS

(set the correct proxy hostname:port, and the path to id_rsa. When you use git-bash, use slashes in the path to id_rsa)
(My version of mysgit includes connect.exe, so I do not need to download and compile connect.c).

Now ssh github.com should work

Note that if you want to connect via a socks5 proxy, then change -H to -S.

ProxyCommand connect -S proxy.server.name:1080 %h %p

If you use a Linux file system, the file permission of ~/.ssh/config must be 600, but on a standard NTFS windows partition, these kind of permissions do not exist.

If your proxy requires NTLM authentication, you can use cntlm, see also this answer.

具体用哪种协议与 git add remote <url>相关

各种协议转换

未经允许不得转载:Mr.Zhang » Git代理

评论 抢沙发

评论前必须登录!