BG1REN's BLOG

Technology, Life, and Infinite Possibilities...


Configuring Git Proxy Server

How to use github.com in “restricted” network environments is a common challenge for many programmers. This article introduces methods to configure proxy servers for git, hoping to provide some assistance.

HTTP/HTTPS Proxy

To make git use the HTTP/HTTPS proxy server 127.0.0.1:10808 when accessing repositories on https://github.com, while connecting directly to other repositories, you can run:

git config --global http.https://github.com.proxy http://127.0.0.1:10808

This will add the following content to your global Git configuration file:

[http "https://github.com"]
    proxy = http://127.0.0.1:10808

SOCKS Proxy

If you access github.com repositories via the SSH protocol, HTTP/HTTPS proxies won’t work. In this case, you can solve the problem by configuring a SOCKS proxy for SSH.

Your system needs to have the nc command (using BSD’s netcat which supports the -x parameter for proxy settings). Most operating system distributions can install it through their built-in package managers.

Add the following configuration to your SSH config file (usually $HOME/.ssh/config):

Host github.com
  HostName github.com
  ProxyCommand nc -x 127.0.0.1:10808 -X 5 %h %p

After configuration, all SSH connections to github.com will go through the configured SOCKS5 proxy.