How to Run git clone Through a Proxy (HTTPS and SSH Remotes)
By the ProxyV4 Engineering Team · Updated:
To run git clone through a proxy, set git config --global http.proxy http://USER:PASS@IP:PORT for HTTPS remotes, or add a ProxyCommand to ~/.ssh/config for SSH remotes, because http.proxy never touches SSH traffic. Below you will find every scope Git supports, the socks5h trick that keeps DNS on the proxy, and fixes for the errors you are most likely to hit.
First, check which transport your remote uses
Git speaks two network transports that matter here, and each is proxied differently. Remotes that start with https:// go through libcurl, which reads http.proxy and the usual proxy environment variables. Remotes written as git@host:org/repo.git or ssh:// go through the OpenSSH client, which ignores all of that and only follows its own config.
git remote -v
# origin https://git.example.com/team/app.git (fetch) <- HTTPS: use http.proxy
# origin [email protected]:team/app.git (fetch) <- SSH: use ProxyCommandPlenty of "my proxy setting does nothing" reports come down to this mismatch. If a repository uses SSH and you only set http.proxy, Git connects directly and you never notice until a firewall blocks it.
git config http.proxy at the scope you actually need
The value follows curl's syntax: scheme://user:password@host:port. With a proxy line delivered as ip:port:user:pass, rearrange it into a URL by hand or with the proxy format converter. Git has no separate https.proxy key; the single http.proxy covers both http:// and https:// remotes, and a https.proxy entry is silently ignored.
One command, global or one repository
Use -c to try a proxy for a single command without saving anything. Once it works, store it globally (in ~/.gitconfig) or inside one repository (in .git/config).
# one-off test, nothing saved
git -c http.proxy=http://USER:[email protected]:PORT clone https://git.example.com/team/app.git
# every repository for this user
git config --global http.proxy http://USER:[email protected]:PORT
# only the repository you are standing in
git config http.proxy http://USER:[email protected]:PORTGit also accepts remote.<name>.proxy, which applies to one remote such as origin. Setting it to an empty string disables proxying for that remote even when a global proxy exists, which is handy for a fork that lives on an internal server.
Per host with http.<url>.proxy
Usually only one server needs the proxy. Git matches http.<url>.* keys against the remote URL by scheme, host, port, path and user name, and the longest path match wins. A * matches one level of subdomain, so https://*.example.com covers git.example.com but not a.b.example.com.
# proxy only for this host
git config --global http.https://git.example.com.proxy http://USER:[email protected]:PORT
# or a single organisation path on that host
git config --global http.https://git.example.com/vendor/.proxy http://USER:[email protected]:PORT
# see what Git resolves for a URL
git config --get-urlmatch http.proxy https://git.example.com/vendor/lib.gitThe --get-urlmatch check is the quickest way to confirm which entry wins before you blame the network.
Git with a SOCKS5 proxy: socks5 versus socks5h
Because libcurl does the work, Git understands SOCKS URLs in http.proxy as well. The scheme decides who resolves the hostname. With socks5://, your machine looks up git.example.com and hands the proxy an IP address. With socks5h://, the hostname travels to the proxy, which resolves it on its side.
git config --global http.proxy socks5h://USER:[email protected]:PORTPrefer socks5h in two cases: when the Git server's name only resolves correctly from the proxy's network, and when local DNS is filtered or you do not want lookups to reveal which hosts you fetch from. Note that SOCKS5 in Git only applies to HTTPS remotes; SSH remotes still need the setup further down.
If you are unsure which protocol a given proxy port accepts, the HTTP vs SOCKS5 guide explains how the two differ and how to tell them apart.
Proxy credentials without leaking them
Anything you put in http.proxy is stored in plain text in a config file, and it shows up in git config --list. That is acceptable on a single-user laptop and a problem on shared build hosts or in screenshots.
Characters that have meaning in a URL must be percent-encoded inside the password: @ becomes %40, : becomes %3A, / becomes %2F and # becomes %23. A password such as p@ss:word is written as p%40ss%3Aword.
- Let Git ask. If the proxy URL contains a user name but no password (
http://[email protected]:PORT), Git requests the password through its credential system, so a credential helper can store it instead of the config file. - Use environment variables in CI. Export
HTTPS_PROXYfrom a secret for the job instead of committing a config file. Git readshttp_proxy,https_proxyandall_proxywhenhttp.proxyis unset. - Pin the auth method only when needed.
http.proxyAuthMethoddefaults toanyauth; set it tobasicif a proxy fails to send a proper 407 challenge.
Git over SSH through a proxy
For SSH remotes, put the proxy in ~/.ssh/config so every tool that uses SSH (Git, scp, rsync) behaves the same. OpenBSD netcat cannot send a SOCKS5 username and password, so use ncat from the Nmap project, which can.
# ~/.ssh/config
Host git.example.com
User git
ProxyCommand ncat --proxy 203.0.113.10:PORT --proxy-type socks5 --proxy-auth USER:PASS %h %pIf you want the proxy for Git only, and not for interactive SSH sessions to the same host, set it on the Git side instead with core.sshCommand, or for one command with the GIT_SSH_COMMAND environment variable.
git config core.sshCommand 'ssh -o ProxyCommand="ncat --proxy 203.0.113.10:PORT --proxy-type socks5 --proxy-auth USER:PASS %h %p"'Some networks block outbound port 22 entirely. GitHub documents an SSH endpoint on port 443 (ssh.github.com), which you can combine with the same ProxyCommand by adding Hostname ssh.github.com and Port 443 to the Host github.com block.
When a dedicated IPv4 helps a Git workflow
A proxy for Git is mostly about where your requests appear to come from. Self-hosted GitLab, Gitea or Bitbucket servers are often firewalled to a short list of source addresses, and vendors that ship code through private repositories frequently restrict access by IP. If your laptop or CI runners change address, a fixed exit IP gives the server admin one address to permit.
That is the job ProxyV4 private datacenter IPv4 proxies are built for: one tenant per IP for the whole term, the address stays the same while the proxy is active, and renewing before expiry keeps it. Each proxy speaks HTTP(S) and SOCKS5 with username and password login, and you can enable both on the same port, so one line covers http.proxy and an ncat ProxyCommand. Traffic on IPv4 is not metered, which matters when you clone large monorepos.
It is not the right tool if all you need is to get through an employer's mandatory proxy; use the one your IT team provides. IPv6 proxies are sold separately, which rarely matters for Git hosts since they all accept IPv4. A single IP can be ordered, so buy one, run your real clone and push through it, check it with the proxy checker, then scale. Live per-IP prices are on the pricing page.
Reading Git's proxy errors
Turn on curl tracing to see the proxy handshake. GIT_TRACE_CURL=1 git ls-remote https://git.example.com/team/app.git prints the CONNECT request, the proxy's reply and the TLS negotiation, with authorization headers redacted.
Received HTTP code 407 from proxy after CONNECT
The proxy rejected your credentials. Check for unencoded special characters first, then for a stale HTTPS_PROXY variable overriding nothing you expected. The 407 Proxy Authentication Required guide covers the remaining causes.
Could not resolve proxy or connection refused
"Could not resolve proxy" means the host part of the proxy URL is wrong or contains a stray character. A refused or timed-out connection usually means the wrong port or a protocol mismatch, such as an http:// URL pointed at a SOCKS-only port. If you changed the proxy's protocol mode, the port may have changed too, so copy the line again.
Received HTTP code 403 from proxy after CONNECT
The proxy accepted your login but refused the destination. Some HTTP proxies only allow CONNECT to port 443, which breaks remotes on custom ports. Switching the same proxy to socks5h:// often avoids the restriction; otherwise ask the provider which ports are open.
Turning the proxy off again
Remove each scope you set, then confirm nothing is left. Environment variables survive config changes, so check them too.
git config --global --unset http.proxy
git config --global --unset http.https://git.example.com.proxy
git config --show-origin --get-regexp 'proxy'
env | grep -i _proxyFrequently asked questions
Does git config http.proxy also apply to SSH remotes?
No. http.proxy only affects remotes that use https:// or http://. SSH remotes follow ~/.ssh/config, core.sshCommand or GIT_SSH_COMMAND, so they need a ProxyCommand.
Should I set https.proxy as well as http.proxy?
No. Git has no https.proxy key and ignores it. The single http.proxy setting applies to both HTTP and HTTPS remotes.
Can git clone use a SOCKS5 proxy with a username and password?
Yes for HTTPS remotes: set http.proxy to socks5h://USER:PASS@IP:PORT. For SSH remotes, use ncat --proxy-type socks5 --proxy-auth USER:PASS in a ProxyCommand.
How do I bypass the proxy for one internal Git server?
Set remote.<name>.proxy to an empty string for that remote, or add the host to the NO_PROXY environment variable if you configured the proxy through environment variables.
Will the proxy IP change between clones?
With a ProxyV4 private IPv4 or static ISP proxy, no. The address stays the same while the proxy is active, and renewing before it expires keeps the same IP, so a server-side firewall rule keeps working.
Reach IP-restricted Git servers from one fixed IP
Get a private IPv4 that only you use, with HTTP(S) and SOCKS5 on one port and unmetered traffic. Order a single IP, test your clone, then add more.
See live prices