git: Proxy CONNECT aborted

git clone through a proxy with a login stops before it reaches the server. One config line sends the login on the first try.

4 min read
git clone through an authenticated proxy fails with Proxy CONNECT aborted; with http.proxyAuthMethod set to basic the CONNECT carries the login and the clone works.git clone https://… through a proxy with a loginCONNECT github.com:443no Proxy-Authorization yetfatal: unable to access …: Proxy CONNECT abortedgit config --global http.proxyAuthMethod basicCONNECT github.com:443Proxy-Authorization: Basic …200HTTPS remotes only · SSH remotes ignore http.proxy

In short

Run git config --global http.proxyAuthMethod basic. git then sends the proxy login with the first CONNECT instead of waiting for a 407 that the proxy answers by closing the connection. If you get 407 from proxy after CONNECT instead, the login itself is wrong.

http.proxyAuthMethod basichttps:// remotes only

git doesn’t speak HTTP itself. For https:// remotes it hands the request to libcurl, and libcurl opens a tunnel through the proxy with CONNECT github.com:443. Everything inside that tunnel is encrypted; the proxy only ever sees the CONNECT line and its headers.

By default (anyauth) curl doesn’t know which login method the proxy wants, so it asks without one, reads the Proxy-Authenticate header of the 407 and tries again on the same connection. Many proxies close the connection right after the 407. curl then has no connection left to retry on, and git prints:

txt
fatal: unable to access 'https://github.com/user/repo.git/': Proxy CONNECT aborted

Residential proxy gateways, ours included, take a Basic login. Telling git that up front (http.proxyAuthMethod basic) puts Proxy-Authorization: Basic … on the very first CONNECT, and the round trip that breaks never happens.

The proxy closes after the 407

The case above: the login is right, but git never gets to send it. http.proxyAuthMethod basic fixes it for every repository; GIT_HTTP_PROXY_AUTHMETHOD=basic does the same for one command.

abortedhttp.proxyAuthMethod anyauth (default)login never sent
200http.proxyAuthMethod basiclogin on the first CONNECT

The login is wrong

Received HTTP code 407 from proxy after CONNECT means the proxy read the login and refused it. Copy user and password again from your provider. A password with @, :, # or / must be percent-encoded inside http.proxy: which characters and how. The same message from curl is covered in curl: (56) CONNECT tunnel failed, response 407.

The remote is SSH

git@github.com:user/repo.git goes over SSH, and SSH ignores http.proxy completely. Either switch the remote to HTTPS (git remote set-url origin https://github.com/user/repo.git) or give SSH a ProxyCommand. Most nc builds can’t send a proxy login, so with an authenticated proxy HTTPS is the simpler way.

An old proxy from the environment

curl also reads https_proxy, HTTPS_PROXY and all_proxy. A variable left over from another tool sends git to a proxy you forgot about. env | grep -i proxy shows them; git config --show-origin --get-regexp proxy shows which git config file sets one.

SettingWhat it does
http.proxyProxy for http:// and https:// remotes: http://USER:PASS@host:port
http.proxyAuthMethodanyauth (default), basic, digest, negotiate, ntlm
http.https://github.com.proxyProxy for one host only
http.noProxy / NO_PROXYHosts that skip the proxy (curl reads the variable)
GIT_HTTP_PROXY_AUTHMETHODSame as http.proxyAuthMethod, for one shell or command
--unset http.proxyBack to a direct connection

Names as in the git-config documentation. SSH remotes use none of these.

A setup that works

Replace USER and PASS with your proxy login. Port 9000 gives a new IP per connection; that is fine for git.

terminal
git config --global http.proxy "http://USER-country-us:PASS@via.proxies.vision:9000"
git config --global http.proxyAuthMethod basic

git clone https://github.com/git/git.git --depth 1

Only for one host, or one command

git config --global http.https://github.com.proxy "http://USER:PASS@via.proxies.vision:9000" limits the proxy to GitHub. For a single clone without touching any config: git -c http.proxy=http://USER:PASS@via.proxies.vision:9000 -c http.proxyAuthMethod=basic clone …

Targeting goes into the username as usual: USER-country-de for an exit in Germany. A socks5h:// URL on port 11000 works in http.proxy too, since curl handles SOCKS5 itself.

What does 'Proxy CONNECT aborted' mean in git?
git talks to HTTPS remotes through libcurl. With a proxy that needs a login, curl first sends the CONNECT without credentials and waits for the 407 to learn which method to use. If the proxy closes the connection instead of keeping it open for the second try, curl gives up with Proxy CONNECT aborted. Setting http.proxyAuthMethod to basic makes curl send the login with the first CONNECT.
How do I set a proxy with username and password for git?
git config ‑‑global http.proxy http://USER:PASS@host:port, plus git config ‑‑global http.proxyAuthMethod basic. Percent-encode special characters in the password (@ becomes %40). The setting covers https:// remotes; git uses the same key for both.
Why does git still connect directly with http.proxy set?
The remote is probably SSH (git@github.com:user/repo.git). http.proxy only applies to http:// and https:// remotes. Switch the remote to its https:// URL, or route SSH through the proxy with a ProxyCommand.
How do I use a proxy for only one host in git?
Use the per-URL form: git config ‑‑global http.https://github.com.proxy http://USER:PASS@host:port. Other remotes keep connecting directly.
How do I remove the git proxy setting?
git config ‑‑global ‑‑unset http.proxy and git config ‑‑global ‑‑unset http.proxyAuthMethod. Also check the environment: https_proxy, HTTPS_PROXY and all_proxy are read by curl even without any git config.

Residential proxies, pay per GB

HTTP and SOCKS5. Country, city and sticky sessions in the username. No subscription.