The 'Failed to connect to proxy' error occurs when Git is configured to use a proxy server that is unavailable, unreachable, or incorrectly configured. This commonly happens when proxy settings from a corporate environment persist after leaving the network, or when environment variables override Git's connection settings.
The "Failed to connect to proxy" error indicates that Git attempted to route its HTTP/HTTPS traffic through a proxy server, but the connection to that proxy failed. This error typically appears as: ``` fatal: unable to access 'https://github.com/...': Failed to connect to proxy.company.com port 8080 ``` Git uses proxy settings from multiple sources (in order of precedence): 1. Repository-level Git config (`.git/config`) 2. User-level Git config (`~/.gitconfig`) 3. System-level Git config (`/etc/gitconfig`) 4. Environment variables (`http_proxy`, `https_proxy`, `HTTP_PROXY`, `HTTPS_PROXY`) The proxy server specified in these settings is either: - Not running or accessible at the configured address/port - Behind a firewall or network that's currently unreachable - Incorrectly configured (wrong hostname, port, or protocol) - No longer needed because you've left the network that requires it This error is extremely common when developers switch between corporate networks (which require proxies) and home networks (which typically don't).
First, identify where the proxy configuration is coming from:
# Check all proxy-related Git configuration
git config --global --get http.proxy
git config --global --get https.proxy
git config --get http.proxy
git config --get https.proxy
# List all Git config to find proxy entries
git config --list --show-origin | grep -i proxyThis will show you the exact file and line where proxy settings are defined. Note the location for the next steps.
If Git config has proxy settings you no longer need, remove them:
# Remove global proxy settings
git config --global --unset http.proxy
git config --global --unset https.proxy
# Remove local (repository-level) proxy settings
git config --unset http.proxy
git config --unset https.proxy
# If you have multiple values, remove all of them
git config --global --unset-all http.proxy
git config --global --unset-all https.proxyVerify the settings are removed:
git config --list | grep proxyIf no output appears, Git's proxy configuration is cleared.
Proxy settings can also come from environment variables:
On Linux/macOS:
# Check current proxy environment variables
echo $http_proxy
echo $https_proxy
echo $HTTP_PROXY
echo $HTTPS_PROXY
echo $all_proxy
echo $no_proxy
# Unset them for the current session
unset http_proxy
unset https_proxy
unset HTTP_PROXY
unset HTTPS_PROXY
unset all_proxy
# Test Git after unsetting
git clone https://github.com/octocat/Hello-World.git /tmp/test-repoOn Windows (Command Prompt):
echo %http_proxy%
echo %https_proxy%
set http_proxy=
set https_proxy=On Windows (PowerShell):
$env:http_proxy
$env:https_proxy
Remove-Item Env:http_proxy -ErrorAction SilentlyContinue
Remove-Item Env:https_proxy -ErrorAction SilentlyContinueIf unsetting variables fixes the issue, make it permanent:
On Linux/macOS, check these files for proxy exports:
# Common locations for proxy settings
grep -r "proxy" ~/.bashrc ~/.bash_profile ~/.zshrc ~/.profile 2>/dev/nullRemove or comment out lines like:
# export http_proxy=http://proxy.company.com:8080
# export https_proxy=http://proxy.company.com:8080Then reload your shell:
source ~/.bashrc # or ~/.zshrcOn Windows, remove system environment variables:
1. Press Win + R, type sysdm.cpl, press Enter
2. Go to Advanced tab > Environment Variables
3. Look for http_proxy, https_proxy in both User and System variables
4. Select and Delete any proxy-related variables
5. Click OK and restart your terminal
If the above commands don't work, edit the Git configuration file directly:
Location of .gitconfig:
- Linux/macOS: ~/.gitconfig
- Windows: C:\Users\YourUsername\.gitconfig
Open the file and remove or comment out proxy sections:
# Before (with proxy):
[http]
proxy = http://proxy.company.com:8080
[https]
proxy = http://proxy.company.com:8080
# After (proxy removed):
[http]
# proxy = http://proxy.company.com:8080
[https]
# proxy = http://proxy.company.com:8080Also check the local repository config at .git/config in your project directory for any proxy settings.
If you're behind a corporate proxy and need to configure it correctly:
# Basic proxy configuration
git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080
# Proxy with authentication
git config --global http.proxy http://username:[email protected]:8080
# For SOCKS5 proxy
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080Finding your proxy settings:
- Windows: Control Panel > Internet Options > Connections > LAN Settings
- macOS: System Preferences > Network > Advanced > Proxies
- Linux: Check with your network administrator or in system settings
Special characters in passwords must be URL-encoded:
- @ becomes %40
- : becomes %3A
- # becomes %23
If you need a proxy for most traffic but want to bypass it for certain hosts:
# Bypass proxy for internal Git servers
git config --global http.https://internal-git.company.com.proxy ""
# Set no_proxy environment variable
export no_proxy="localhost,127.0.0.1,.company.com,internal-git.company.com"Add to your shell profile to make permanent:
echo 'export no_proxy="localhost,127.0.0.1,.company.com"' >> ~/.bashrcFor a one-time clone without modifying global settings:
# Clone bypassing proxy entirely
git clone --config http.proxy="" --config https.proxy="" https://github.com/user/repo.git
# Clone with a specific proxy for this operation only
git clone --config http.proxy=http://proxy:8080 https://github.com/user/repo.git
# Using environment variable override
http_proxy="" https_proxy="" git clone https://github.com/user/repo.gitThis is useful for testing whether the proxy is the issue without changing your configuration.
Some tools and systems configure proxies globally:
Check for Fiddler/Charles Proxy residue:
These debugging tools often set system-wide proxy settings. Check if they're running or have left configuration behind.
On macOS, check system proxy:
networksetup -getwebproxy "Wi-Fi"
networksetup -getsecurewebproxy "Wi-Fi"On Linux, check for system proxy (GNOME):
gsettings get org.gnome.system.proxy mode
gsettings get org.gnome.system.proxy.http host
gsettings get org.gnome.system.proxy.http portOn Windows, check registry:
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer### Proxy Configuration Precedence
Git checks proxy settings in this order (first match wins):
1. remote.<name>.proxy - Per-remote configuration
2. http.<url>.proxy - URL-specific proxy
3. http.proxy / https.proxy - Global Git proxy config
4. https_proxy / HTTPS_PROXY - Environment variables
5. http_proxy / HTTP_PROXY - Environment variables
6. System proxy settings (varies by OS)
### Debugging Proxy Issues with GIT_CURL_VERBOSE
Enable verbose output to see exactly what Git is doing:
GIT_CURL_VERBOSE=1 git clone https://github.com/user/repo.gitThis shows:
- Which proxy Git is trying to use
- Connection attempts and failures
- SSL/TLS negotiation details
- HTTP headers and responses
### Authenticated Proxy Configuration
For proxies requiring authentication, you have several options:
Option 1: Inline credentials (not recommended for shared systems)
git config --global http.proxy http://user:pass@proxy:8080Option 2: Use .netrc file (Linux/macOS)
# ~/.netrc
machine proxy.company.com
login your_username
password your_passwordSecure the file:
chmod 600 ~/.netrcOption 3: Use Git credential helper
git config --global credential.helper store
# Git will prompt for credentials on first use### NTLM/Kerberos Corporate Proxies
For corporate environments using NTLM or Kerberos authentication:
# Using CNTLM (NTLM authenticating proxy)
# Install cntlm and configure it as a local proxy
git config --global http.proxy http://127.0.0.1:3128Or use px proxy for Windows NTLM:
# px runs locally and handles NTLM auth
git config --global http.proxy http://127.0.0.1:3128### SSH as Alternative to HTTP/HTTPS
If proxy configuration remains problematic, consider using SSH instead:
# Change remote URL to SSH
git remote set-url origin [email protected]:user/repo.git
# SSH can also be proxied if needed
# Add to ~/.ssh/config:
Host github.com
ProxyCommand nc -X connect -x proxy.company.com:8080 %h %p### PAC (Proxy Auto-Configuration) Files
Some networks use PAC files for dynamic proxy configuration. Git doesn't natively support PAC files, but you can:
1. Find the actual proxy by opening the PAC URL in a browser
2. Use a PAC resolver like pacparser to determine which proxy to use
3. Configure the resolved proxy in Git directly
### Multiple Network Environments
If you frequently switch between networks with different proxy requirements, consider using Git aliases:
# Add aliases for different environments
git config --global alias.office-pull '!git -c http.proxy=http://corp-proxy:8080 pull'
git config --global alias.home-pull '!git -c http.proxy="" pull'
# Use as:
git office-pull origin main
git home-pull origin mainOr create shell functions:
# In ~/.bashrc or ~/.zshrc
git-office() {
http_proxy=http://proxy:8080 https_proxy=http://proxy:8080 git "$@"
}
git-home() {
http_proxy="" https_proxy="" git "$@"
}### Proxy and Certificate Issues
Proxies that perform SSL interception can cause certificate errors alongside proxy issues. If you see SSL errors after fixing proxy connectivity, you may need to:
# Add corporate CA certificate (recommended)
git config --global http.sslCAInfo /path/to/corporate-ca.crt
# Disable SSL verification (NOT recommended, security risk)
git config --global http.sslVerify falsekex_exchange_identification: Connection closed by remote host
Connection closed by remote host when connecting to Git server
fatal: unable to access: Proxy auto-configuration failed
How to fix 'Proxy auto-configuration failed' in Git
fatal: unable to access: Authentication failed (proxy requires basic auth)
How to fix 'Authentication failed (proxy requires basic auth)' in Git
fatal: unable to access: no_proxy configuration not working
How to fix 'no_proxy configuration not working' in Git
fatal: unable to read tree object in treeless clone
How to fix 'unable to read tree object in treeless clone' in Git