Git: "Received HTTP code 407 from proxy after CONNECT" with Azure DevOps
HTTP 407 is the answer of a proxy, not of Azure DevOps: the proxy between your computer and the internet wants a login before it opens the connection to dev.azure.com, and Git did not give one. Your personal access token never left your computer. Tell Git the proxy and your proxy user name (git config --global http.proxy http://user@proxy.example.com:8080), let Git ask for the password, and set http.proxyAuthMethod if the proxy does not use the method Git picks.
What it looks like
fatal: unable to access 'https://dev.azure.com/contoso/Project/_git/repo/': Received HTTP code 407 from proxy after CONNECT
Older curl versions, which Git on older Linux distributions still uses, word the same thing as CONNECT tunnel failed, response 407 (a public report with another Git host). The address in the message does not matter. "Authentication failed" is the opposite case: Azure DevOps was reached and refused the token.
The IDE has its own proxy settings: Azure DevOps Pull Requests, a plugin for JetBrains IDEs, sends its requests through the proxy and the proxy login that the IDE keeps, not through Git's.
1. See which proxy Git uses
Git takes the proxy from its own setting http.proxy, and when that is empty from the environment variables http_proxy, https_proxy and all_proxy (git-config). Look at both:
git config --show-origin --get-regexp "http.*proxy"
Windows PowerShell:
Get-ChildItem Env: | Where-Object Name -match 'proxy'
macOS and Linux:
env | grep -i proxy
Nothing in either list while you are behind a proxy means Git goes out without one, and the proxy answers 407 to a client it cannot identify. Your browser gets its proxy from the system settings or an automatic configuration script; the proxy's address is in your browser's or operating system's proxy settings.
2. Give Git the proxy and your login
The format is [protocol://][user[:password]@]proxyhost[:port]. With a user name and no password, Git asks for the password the way it asks for other credentials, so the password does not end up in .gitconfig:
git config --global http.proxy "http://jsmith@proxy.example.com:8080"
Use your own proxy user name. A user name with a backslash or other special characters has to be URL-encoded inside the proxy URL. Then try the command again:
git ls-remote https://dev.azure.com/contoso/Project/_git/repo
3. The proxy's authentication method
http.proxyAuthMethod takes effect only when the proxy string has a user name. The default anyauth lets Git pick from what the proxy offers in its 407 answer; the other values are basic, digest, negotiate and ntlm. Set one when the first try still ends in 407:
git config --global http.proxyAuthMethod negotiate
Which one your proxy wants is a question for whoever runs it, or for the Proxy-Authenticate lines in the output of git ls-remote <URL> run with the environment variable GIT_TRACE_CURL set to 1 (PowerShell: $env:GIT_TRACE_CURL = 1). The trace can contain credentials; do not paste it anywhere.
4. One host through the proxy, another not
Any http.* setting can be limited to a URL (http.<url>.*):
git config --global http.https://dev.azure.com.proxy "http://jsmith@proxy.example.com:8080"
To stop Git from using a proxy for one repository's remote, set the remote's proxy to the empty string:
git config remote.origin.proxy ""
5. The proxy has to let Azure DevOps through
If the 407 stays after a correct login, the proxy's rules may not include Azure DevOps. Microsoft's list of allowed domain URLs includes dev.azure.com, *.dev.azure.com, *.visualstudio.com and login.microsoftonline.com on port 443; SSH needs ssh.dev.azure.com on port 22. A proxy that opens HTTPS to look inside it presents its own certificate, which gives a different message: unable to get local issuer certificate. Git's manual adds that a proxy must be transparent, not modify or buffer requests, or Git can break in various ways.
In the IDE
Azure DevOps Pull Requests, a plugin by Lesstep for JetBrains IDEs 2024.1 or later and Android Studio, uses the IDE's HTTP Proxy settings (Settings | Appearance & Behavior | System Settings | HTTP Proxy): manual, automatic configuration or auto-detect, and the proxy login that the IDE keeps. When a proxy answers 407, the plugin answers with that login and sends the request again. If the proxy still refuses, the plugin says "The proxy asked for a login and did not accept one" and points to that settings page. Git's own fetch, pull and push in the IDE do not use these settings; they use the Git settings above, so the plugin can work while Git fails with 407, or the other way round. The review inbox is free; voting, commenting and completing are Pro, with a 30-day trial.
Get it on JetBrains Marketplace
Azure DevOps is a trademark of Microsoft Corporation; IntelliJ IDEA and Rider are trademarks of JetBrains s.r.o. This page is not affiliated with or endorsed by Microsoft or JetBrains.
More: Git push "RPC failed; HTTP 413" · Git "Authentication failed" · Azure DevOps Server "unable to get local issuer certificate" · "could not read Username" · 日本語