Using a socks proxy with git for the http transport

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

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

  • How do I code against one github repo on 2 computers?
  • Netbeans 7.3: Error connecting to Git repository with SSH
  • Git ignore all files except those of a particular extension, even under subdirectories
  • Git Python Cannot find Commit
  • Git-Diff vs. Git-log? What's the difference?
  • converting only parts of a subversion repository from git
  • Also i have configured my .curlrc file to defined the socks proxy and i can fetch informations directly with curl command like:


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

    git clone

  • Fatal error on “git add submodule”
  • Git Merge Recursive Ours - Command Syntax Example
  • Getting rid of “git: /usr/local/lib/ no version information available (required by git)”
  • Few files out of sync but git doesn't seem to notice
  • Heroku Create Command Yielding “ENOENT” Error
  • Managing Git Users and Passwords
  • 5 Solutions collect form web for “Using a socks proxy with git for the http transport”

    I tested with Git 1.8.2 and SOCKS v5 proxy, following setting works for me:

    git config --global http.proxy 'socks5://'

    UPDATE 2017-3-31:

    According to the document, despite the name http.proxy, it should work for both HTTP and HTTPS repository urls. Thanks @user for pointing out this.

    If you do not want to set the proxy as global config, try ALL_PROXY= e.g.:

    $ ALL_PROXY=socks5:// git clone

    For the git:// protocol we have Using Git with a SOCKS proxy. However, it appears that git does not properly support socks proxies. git itself is linked to libcurl. So the .curlrc file is not used (that is just for the curl command line client). However, the following patch provides the necessary support. With this patch applied to git we can simply set the ALL_PROXY environment variable or HTTP_PROXY or HTTPS_PROXY to socks://hostname:portnum (or socks4/socks5) or indeed the http.proxy git config setting and libcurl will now actually use the socks protocol when using the proxy.

    For example, an active trace:

    $ GIT_CURL_VERBOSE=1 bin-wrappers/git -c "http.proxy=socks://localhost:1080" ls-remote
    * Couldn't find host in the _netrc file; using defaults
    * About to connect() to proxy localhost port 1080 (#0)
    *   Trying
    * connected
    * SOCKS4 request granted.
    * Connected to localhost ( 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 ...

    The necessary patch:

    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);
            return result;

    (Just a little reminder) If you want the hostname also be resolved by the proxy (that means passing everything through the proxy), especially when you are cloning a gist, you can use the following setting (the key is that it uses socks5h instead of socks5):

    git config --global http.proxy socks5h://

    I use the following command to clone a specific repository from socks5 proxy. The proxy settings are specified with --config option.

    $ git clone --config 'http.proxy=socks5://'
    Git Baby is a git and github fan, let's start git clone.