How to access git repository through http proxy?

  1. Install socat. E.g., on SUSE:
    zypper in socat
    
  2. Download this file:
    #!/bin/sh
    # Use socat to proxy git through an HTTP CONNECT firewall.
    # Useful if you are trying to clone git:// from inside a company.
    # Requires that the proxy allows CONNECT to port 9418.
    #
    # Save this file as gitproxy somewhere in your path (e.g., ~/bin) and then run
    #   chmod +x gitproxy
    #   git config --global core.gitproxy gitproxy
    #
    # More details at http://tinyurl.com/8xvpny
    
    # Configuration. Common proxy ports are 3128, 8123, 8000.
    _proxy=proxy.yourcompany.com
    _proxyport=3128
    
    exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
    
  3. Rename its name as gitproxy, and modify _proxy and _proxyport.
  4. Copy it into your PATH , e.g., /usr/bin.
  5. Switch to the directory which contains gitproxy, and execute the following commands:
    # chmod +x gitproxy
    # git config --global core.gitproxy gitproxy
    
  6. Now, git clone git://... will work!