If you are trying to use the git command line interface with an Internet hosted repository, such as
github.com, from within a network that requires a proxy for outbound connections, this post shows you how to
configure the git CLI to use a network proxy. This post also shows you how to provide authentication credentials (username and password),
if your proxy requires it. The git config command is used to set a network proxy.
This command also support the
--local options that control whether the settings are stored globally or in the current git repository location.
Example 1: HTTP Proxy Using Default Port 80 and no Authentication
If your proxy uses the http protocol and the default port 80 and does not require authentication, you can set it with:
git config --global http.proxy http://proxy.myorg.com
Example 2: HTTP Proxy Using Non-Default Port and Authentication
If your proxy uses a custom port, for example 8080, and requires authentication, e.g. a username and a password, you can set it like this:
git config --global http.proxy http://username:firstname.lastname@example.org:8080
Example 3: NTLM Proxy with Authentication and Domain
It may also be necessary to pass a domain name as part of the proxy url, e.g. when using a NTLM proxy. You can accomplish this with the below command:
git config --global http.proxy http://domain\\username:[email protected]:8080
Escaping Special Characters in the Username and Password Parameters
If the username or password contains special characters, those need to be encoded according to HTML URL encoding rules.
For example, if your password is
[email protected], the
@ character needs to be encoded using
git config --global http.proxy http://domain\\username:P%40ssW0rd@proxy.myorg.com:8080
Viewing the Current Proxy and Unsetting the Proxy
To check what the current git proxy setting is, you can use the
git config --global --list
The network proxy can be unset using the
git config --global --unset http.proxy
For two related posts on this blog, have a look at the following links.