Yve*_*eau 66 git ssh proxy socks
如何让git使用socks代理进行http传输?
我成功地使用GIT_PROXY_COMMAND配置git以使用socks代理进行GIT传输.
此外,我已经配置我的.curlrc文件来定义socks代理,我可以直接用curl命令获取信息,如:
curl http://git.kernel.org/pub/scm/git/git.git/info/refs?service=git-upload-pack
Run Code Online (Sandbox Code Playgroud)
但是如何使用带git的socks代理来使用http传输协议检索数据,如:
git clone http://git.kernel.org/pub/scm/git
Run Code Online (Sandbox Code Playgroud)
Yan*_*g.Y 116
我使用Git 1.8.2和SOCKS v5代理进行测试,以下设置为我工作:
git config --global http.proxy 'socks5://127.0.0.1:7070'
更新2017-3-31:
根据该文档,尽管名称,它应该适用于HTTP和HTTPS存储库URL.感谢@user指出这一点.http.proxy
更新2018-11-27:
要禁用代理,请运行命令:
git config --global --unset http.proxy
ohh*_*hho 41
如果您不想将代理设置为全局配置,请尝试以下操作ALL_PROXY=:
$ ALL_PROXY=socks5://127.0.0.1:8888 git clone https://github.com/some/one.git
Run Code Online (Sandbox Code Playgroud)
thu*_*zhf 30
(只是一点提醒)如果你想让主机名也被代理解析(这意味着通过代理传递一切),特别是当你克隆一个要点时,你可以使用以下设置(关键是它使用socks5h代替of socks5):
git config --global http.proxy socks5h://127.0.0.1:1080
Run Code Online (Sandbox Code Playgroud)
我使用以下命令从socks5代理克隆特定的存储库.代理设置使用--config选项指定.
$ git clone https://github.com/xxxxx --config 'http.proxy=socks5://127.0.0.1:1234'
Run Code Online (Sandbox Code Playgroud)
对于git://协议,我们使用Git和SOCKS代理.但是,似乎git不能正确支持socks代理.git本身与libcurl相关联.因此不使用.curlrc文件(仅适用于curl命令行客户端).但是,以下补丁提供了必要的支持.将此补丁应用于git,我们可以简单地将ALL_PROXY环境变量或HTTP_PROXY或HTTPS_PROXY设置为socks://hostname:portnum(或socks4/socks5),或者实际上http.proxy git config设置和libcurl现在实际上在使用代理时使用socks协议.
例如,活动跟踪:
$ GIT_CURL_VERBOSE=1 bin-wrappers/git -c "http.proxy=socks://localhost:1080" ls-remote http://github.com/patthoyts/tclftd2xx.git
* Couldn't find host github.com in the _netrc file; using defaults
* About to connect() to proxy localhost port 1080 (#0)
* Trying 127.0.0.1...
* connected
* SOCKS4 request granted.
* Connected to localhost (127.0.0.1) port 1080 (#0)
> GET /patthoyts/tclftd2xx.git/info/refs?service=git-upload-pack HTTP/1.1
User-Agent: git/1.8.1.msysgit.1.dirty
... and on to a successful request ...
Run Code Online (Sandbox Code Playgroud)
必要的补丁:
diff --git a/http.c b/http.c
index 3b312a8..f34cc75 100644
--- a/http.c
+++ b/http.c
@@ -322,6 +322,14 @@ static CURL *get_curl_handle(void)
if (curl_http_proxy) {
curl_easy_setopt(result, CURLOPT_PROXY, curl_http_proxy);
curl_easy_setopt(result, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+#if LIBCURL_VERSION_NUM >= 0x071800
+ if (!strncmp("socks5", curl_http_proxy, 6))
+ curl_easy_setopt(result, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
+ else if (!strncmp("socks4a", curl_http_proxy, 7))
+ curl_easy_setopt(result, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4A);
+ else if (!strncmp("socks", curl_http_proxy, 5))
+ curl_easy_setopt(result, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
+#endif
}
return result;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
52580 次 |
| 最近记录: |