96

How to make git use a socks proxy for HTTP transport?

I succeed in configuring git with GIT_PROXY_COMMAND to use a socks proxy for GIT transport.

Also, I have configured my .curlrc file to defined the socks proxy and I can fetch information directly with curl command like:

curl http://git.kernel.org/pub/scm/git/git.git/info/refs?service=git-upload-pack

But how to use a socks proxy with git to retrieve data using the HTTP transport protocol like:

git clone http://git.kernel.org/pub/scm/git
4

8 に答える 8

18

次のコマンドを使用して、socks5 プロキシから特定のリポジトリを複製します。プロキシ設定はオプションで指定し--configます。

$ git clone https://github.com/xxxxx --config 'http.proxy=socks5://127.0.0.1:1234'
于 2015-08-16T15:36:04.497 に答える
7

注:ここでのパッチは、バージョン2.4.11の2015年にgitに適用されました。それ以降は、http.proxy構成設定でsocks://urlsを使用できます。

git://プロトコルについては、SOCKSプロキシでのGitの使用があります。ただし、gitはソックスプロキシを適切にサポートしていないようです。git自体はlibcurlにリンクされています。したがって、.curlrcファイルは使用されません(これは、curlコマンドラインクライアント専用です)。ただし、次のパッチは必要なサポートを提供します。このパッチをgitに適用すると、ALL_PROXY環境変数またはHTTP_PROXYまたはHTTPS_PROXYをsocks://hostname:portnum(またはsocks4 / socks5)に設定するか、実際にhttp.proxygitconfig設定と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 ...

必要なパッチ:

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;
于 2013-03-05T16:03:37.343 に答える