Git 目前支持的三种协议 git
、ssh
和 http
,其代理配置各不相同:
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 includesconnect.exe
, so I do not need to download and compile connect.c).Now
ssh github.com
should workNote 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>相关