Setting Proxy for Git



Git proxies can be a bit tricky to set up, as my recent experience helping a friend showed. But after some trial and error, we finally got it working. In this article, I'll share the insights and lessons learned from our journey.

Some Basics

When it comes to proxies for Git, there are two main protocols to consider: SOCKS and HTTP. Both of these can be used seamlessly with Git. Nowadays, when we mention SOCKS, we almost always refer to SOCKS5. In this article, I'll use SOCKS5 as an example.

Git also supports two primary remote URL protocols: HTTP(s) and SSH. For instance, is an HTTP(s) remote URL, while ssh:// is an SSH remote URL.

Set it up

Let's dive into setting up Git proxies with different configurations:

Git Protocol Proxy Protocol Configuration File Config
HTTP(s) HTTP ~/.gitconfig git config --global http.proxy
HTTP(s) SOCKS ~/.gitconfig git config --global http.proxy socks5h://
SSH HTTP ~/.ssh/config Host
  ProxyCommand nc -v -X connect -x %h %p
SSH SOCKS ~/.ssh/config Host
  ProxyCommand nc -v -X 5 -x %h %p

Some Tips

Here are a few tips:


Setting up a proxy for Git doesn't have to be daunting, but it does involve configuring different settings in various files. I trust this article has provided you with the guidance you need to smoothly integrate proxies into your Git workflow.