How to Configure a Proxy for Git Clone and Fetch

An HTTPS Git remote can use an HTTP proxy. Test the route with a read-only Git command and choose a configuration scoped to the command, repository or remote that needs it.

Two tall server cabinets linked by green cables to a central network appliance

Check whether your Git remote uses HTTPS

Open the repository and run git remote -v locally to see its fetch and push addresses. For a first clone, check the URL you are about to give Git. This setup applies to remotes such as https://git.example.com/team/project.git. A remote written as git@git.example.com:team/project.git uses SSH. For that connection, use the SSH routing settings supported by your network or obtain the HTTPS clone URL from your repository host. An HTTPS proxy setting in Git applies to its HTTP transport.

The examples use git.example.com for the Git server and proxy.example for the proxy. Replace both with addresses you are authorized to use. The proxy URL starts with http:// because this example connects to the proxy over ordinary HTTP. Git can still reach an HTTPS remote by asking the proxy for a CONNECT tunnel. If your proxy uses TLS for the connection to the proxy itself, use the scheme and hostname provided by its operator. Compare HTTP and HTTPS proxy connections

Test an HTTPS Git remote through a proxy once

Start with ls-remote. It queries a repository for its references without creating a checkout. The -c setting applies to this invocation. Keep it before ls-remote, clone or fetch when you run one of these commands.

git -c "http.proxy=http://proxy.example:3128" ls-remote --exit-code "https://git.example.com/team/project.git" HEAD
git -c "http.proxy=http://proxy.example:3128" clone "https://git.example.com/team/project.git"
git -c "http.proxy=http://proxy.example:3128" fetch origin

Run the first line as the connection test. A successful response for a repository with a published default branch contains an object ID followed by HEAD. Exit status 2 with --exit-code means the requested ref did not match. An empty repository might not have a resolvable HEAD. A successful ref listing confirms access to that endpoint. A full clone can still fail later if transferring the pack exceeds a gateway timeout. Run the second line to clone or the third from an existing checkout to fetch. Git’s ls-remote reference

Git’s HTTP transport also uses proxy environment settings supported by curl, such as https_proxy, when there is no Git proxy override. If Git ignores the proxy you expected, inspect your Git proxy settings and the bypass rules in NO_PROXY or no_proxy. The shell running Git, an IDE and a CI worker can have different environments. A URL-specific or named-remote proxy can also take precedence over a general http.proxy setting. Git’s http.proxy reference and curl proxy environment variables

If a URL-specific rule already matches your remote, make the one-off check specific to that repository too. Put the complete repository URL into the configuration key, followed by .proxy, and pass that same URL to ls-remote. This also makes it easier to compare the checkout’s named-remote configuration with the configuration used for a fresh clone.

git -c "http.https://git.example.com/team/project.git.proxy=http://proxy.example:3128" ls-remote --exit-code "https://git.example.com/team/project.git" HEAD

Scope a Git proxy to one host, path or remote

Use a URL-specific configuration if repositories under one server or path should use the proxy. The --global flag stores this rule for your user account, and the URL limits which remotes it matches. Here the rule applies to HTTPS remotes under git.example.com/team/, including a clone from that path. Git matches the URL’s scheme, host, port and path against the rule, so keep the scheme and expected port consistent. A longer matching path can select a more specific setting. Git’s URL matching rules

git config --global "http.https://git.example.com/team/.proxy" "http://proxy.example:3128"
git ls-remote --exit-code "https://git.example.com/team/project.git" HEAD

In an existing repository, you can instead set a proxy specifically for the remote named origin. Check the remote name before running the command. This stores the proxy in that repository’s local configuration and lets operations on origin use it. If you already had a rule in either scope, preserve its original value before changing it.

git config --local remote.origin.proxy "http://proxy.example:3128"
git ls-remote --exit-code origin HEAD

If you added one of these rules temporarily, remove that exact entry when finished. If you replaced an existing value, restore it. Run the local removal from the same repository.

git config --global --unset "http.https://git.example.com/team/.proxy"
git config --local --unset remote.origin.proxy

Tell proxy authentication from Git authentication and TLS errors

  • 407 during CONNECT. The proxy is asking for valid proxy credentials before it opens a tunnel. Confirm the proxy address and authentication method with its operator. Git supports a proxy URL with a username and no password and can request the password through its credential mechanisms. Follow your organization’s approved setup, and keep passwords or tokens out of commands and configuration files you share. HTTP 407 explained
  • 401 or 403 from the repository side. After a tunnel is open, check the remote URL and credentials for the repository host. A 401 usually calls for checking authentication. A 403 can come from missing repository permissions or an access policy along the destination path. A separately managed proxy can also reject the CONNECT request with 403, so identify which step returned it. Where an HTTP 403 can come from
  • Certificate verification error. Check the hostname, certificate chain and trust store of the Git installation making the request. If your organization inspects HTTPS, use its approved CA trust configuration and keep verification enabled. A standalone curl installation can use a different trust store from Git.

For a separate reachability test, request https://testmyproxies.com/api/my-ip with curl through the same endpoint and compare the reported ip with the proxy’s expected exit. The Git ref query is the check for the repository itself. If you need a Git curl trace, keep it local and review it for sensitive headers, URLs and internal names before sharing excerpts. Run a curl proxy check and Git curl tracing reference

All proxy testing guides · Open the proxy tester