How to Configure a Proxy to Work With Git

John Wachira Feb 02, 2024
  1. Supported Proxy Protocols in Git
  2. Use an HTTP Proxy in Git Commands
  3. Use an HTTPS Proxy in Git Commands
  4. Configure a Proxy Permanently in the Git Config File
  5. Remove Proxy Setting for a Git Repository
  6. Configure a SOCKS Proxy in Git
How to Configure a Proxy to Work With Git

This article will discuss configuring Git to work with different proxies. It is usually hard to access Git while working behind a corporate firewall.

We will cover some of the proxies that Git supports, how to configure them, and how to feed the proxy to our command line for single use. Let’s start.

Supported Proxy Protocols in Git

Git supports the following proxies:

  1. HTTP
  2. HTTPS
  3. SOCKS4
  4. SOCKS5

Use an HTTP Proxy in Git Commands

We normally edit the Git configuration file to use proxies. However, Git allows us to feed the proxy to our terminal for quick use.

Here is an example of an HTTP proxy on the command line.

$ git config --global http.proxy http://username:password@proxy_server.com:port

In a scenario with a specific domain, we will run the command as shown below.

$ git config --global http.http://specific_domain.com.proxy http://username:password@proxy_server.com:port

Note we have added our domain between http.proxy, and we feed the full proxy URL. The full URL makes it possible for Git to automatically recognize and run the protocol.

Use an HTTPS Proxy in Git Commands

In a scenario where we are working behind a firewall, here is how we will run the commands for an HTTPS proxy protocol.

$ git config --global http.https://specific_domain.com.proxy http://username:password@proxy_server.com:port

The URL goes between http.proxy, but note the changes from http://specific_domain.com to https://specific_domain.com.

You can disable SSL verification to avoid problems, as shown below.

$ git config --global http.https://specific_domain.com.sslVerify false

Configure a Proxy Permanently in the Git Config File

We can permanently store the above settings in the Git configuration file. We use the --global switch to set the configs for all users and connections.

Set a Global Proxy With the --Global Switch

If we need all our Git actions to pass through our proxy, we run:

$ git config --global http.proxy http://username:password@proxy_server.com:port

Set a Proxy for a Specific Domain

We will run the command below if we want a specific domain to connect through our proxy.

$ git config --global http.https://domain.com.proxy http://username:password@proxy_server.com:port

Disable HTTPS Verification

If you get this error message unable to access 'https://...': Unknown SSL protocol error in connection to ...:443, you can switch off the SSL verification as shown below.

$ git -c http.sslVerify=false clone https://domain.com/example.git

Alternatively, you can disable it together, as shown below.

$ git config http.sslVerify false

Remove Proxy Setting for a Git Repository

We use the command below to list all proxies connected to our repository.

$ git config --get-regexp http.*

We can use any of the syntaxes below to remove our proxy.

$ git config --unset http.proxy
$ git config --unset http.https://domain.com.proxy

or

$ git config --unset http.sslVerify
$ git config --unset http.https://domain.com.sslVerify

As shown below, we can add the global switch to remove the proxy settings from all our repositories.

$ git config --global --unset http.proxy
$ git config --global --unset http.https://domain.com.proxy

Configure a SOCKS Proxy in Git

As mentioned earlier, Git supports socks5:// and socks4:// protocols.

Run the commands below to configure the SOCKS protocols.

$ git config --global http.proxy socks5://proxy_server.com:port

For a specific domain, run:

$ git config --global http.https://domain.com.proxy socks5://proxy_server.com:port
Author: John Wachira
John Wachira avatar John Wachira avatar

John is a Git and PowerShell geek. He uses his expertise in the version control system to help businesses manage their source code. According to him, Shell scripting is the number one choice for automating the management of systems.

LinkedIn

Related Article - Git Config