The 'SOCKS5 connection to proxy failed' error occurs when Git cannot establish a connection through your configured SOCKS proxy. This typically happens when the proxy server is not running, the configuration is incorrect, or the protocol (socks5 vs socks5h) is mismatched. The fix usually involves verifying your proxy is active or updating your Git proxy configuration.
The "fatal: unable to access: SOCKS5 connection to proxy failed" error indicates that Git is configured to use a SOCKS5 proxy for HTTP/HTTPS connections, but the connection to that proxy cannot be established. Git uses the SOCKS5 protocol to tunnel its traffic through the proxy server, and when this handshake fails, the operation cannot proceed. This error commonly appears when: - A proxy configuration remains in your Git config after you've disconnected from a VPN or stopped running a local proxy (SSH tunnel, Tor, Shadowsocks, etc.) - The proxy server address or port is incorrect - You're using `socks5://` when you should be using `socks5h://` (the "h" variant handles DNS resolution through the proxy) - Network conditions prevent reaching the proxy server The error message comes from the underlying libcurl library that Git uses for HTTP/HTTPS operations. Understanding this helps explain why the same proxy settings work for SSH-based Git operations but fail for HTTPS clones.
First, determine if you still need the proxy. If you configured it for a specific network or VPN that you're no longer using, simply remove the proxy settings:
# Remove global proxy settings
git config --global --unset http.proxy
git config --global --unset https.proxy
# Verify the settings are removed
git config --global --get http.proxy
git config --global --get https.proxyIf these commands return nothing, the global proxy is cleared. Try your Git operation again. If it works, you're done.
Git proxy settings can exist in multiple places. Check all of them:
# Check global config
git config --global --get http.proxy
git config --global --get https.proxy
# Check local repository config (run in repo directory)
git config --local --get http.proxy
git config --local --get https.proxy
# Check system config
git config --system --get http.proxy
# See all proxy-related settings
git config --list | grep -i proxyAlso check for environment variables:
# Linux/macOS
echo $http_proxy
echo $https_proxy
echo $HTTP_PROXY
echo $HTTPS_PROXY
echo $all_proxy
# Windows (PowerShell)
$env:http_proxy
$env:https_proxyTo unset environment variables temporarily:
# Linux/macOS
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY all_proxy
# Windows (PowerShell)
$env:http_proxy = $null
$env:https_proxy = $nullIf you do need the proxy, verify it's actually running and accessible:
# Test connection to your proxy (replace with your proxy address and port)
nc -zv 127.0.0.1 1080
# Or use curl to test
curl -v --proxy socks5://127.0.0.1:1080 https://github.com
# On Windows, use PowerShell
Test-NetConnection -ComputerName 127.0.0.1 -Port 1080Common proxy applications and their default ports:
- SSH dynamic tunnel: Usually 1080 or custom
- Tor: 9050 (SOCKS) or 9150 (Tor Browser)
- Shadowsocks: 1080
- V2Ray/Xray: 10808 or custom
- Clash: 7890
If the proxy isn't running, start it before retrying your Git command.
A common issue is using socks5:// when socks5h:// is needed. The "h" variant performs DNS resolution through the proxy server rather than locally:
# Change from socks5 to socks5h for DNS resolution through proxy
git config --global http.proxy socks5h://127.0.0.1:1080
git config --global https.proxy socks5h://127.0.0.1:1080This is especially important when:
- You're behind a firewall that also blocks DNS
- The destination hostname can only be resolved from within the proxy network
- You're using Tor or similar anonymizing proxies
To revert to local DNS resolution:
git config --global http.proxy socks5://127.0.0.1:1080
git config --global https.proxy socks5://127.0.0.1:1080Instead of a global proxy, you can configure Git to use the proxy only for specific hosts:
# Proxy only for GitHub
git config --global http.https://github.com.proxy socks5h://127.0.0.1:1080
# Proxy only for GitLab
git config --global http.https://gitlab.com.proxy socks5h://127.0.0.1:1080
# Proxy for a corporate Git server
git config --global http.https://git.company.com.proxy socks5h://127.0.0.1:1080This leaves other Git operations unaffected by proxy settings. To remove domain-specific proxy:
git config --global --unset http.https://github.com.proxyYou can also manually edit your Git configuration file:
# Open global gitconfig
nano ~/.gitconfig
# Or on Windows: notepad %USERPROFILE%\.gitconfigRemove or comment out the proxy sections:
# Before (causing the error):
[http]
proxy = socks5://127.0.0.1:1080
[https]
proxy = socks5://127.0.0.1:1080
# After (proxy removed):
# [http]
# proxy = socks5://127.0.0.1:1080
# [https]
# proxy = socks5://127.0.0.1:1080Or update with correct settings:
[http]
proxy = socks5h://127.0.0.1:1080
[https]
proxy = socks5h://127.0.0.1:1080Note that http.proxy settings only affect HTTPS Git URLs. For SSH URLs ([email protected]:...), you need to configure SSH itself:
# Edit SSH config
nano ~/.ssh/configAdd a ProxyCommand:
Host github.com
User git
ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %pFor Windows or if nc isn't available, you can use connect:
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:1080 %h %pThis is necessary when you need to proxy SSH connections, not just HTTPS.
Proper SOCKS5 proxy support was added in Git 2.7 (December 2015). If you're running an older version, Git may incorrectly handle SOCKS proxies:
# Check your Git version
git --version
# Update Git
# Ubuntu/Debian
sudo apt update && sudo apt install git
# macOS with Homebrew
brew upgrade git
# Windows: Download from https://git-scm.com/download/winGit 2.47 (2024) added additional SOCKS5 features like Unix socket support. Consider updating to the latest version for best compatibility.
### Understanding socks5 vs socks5h
The SOCKS5 protocol supports two modes of operation for DNS resolution:
| Protocol | DNS Resolution | Use Case |
|----------|---------------|----------|
| socks5:// | Local (your machine) | When local DNS works and you only need traffic tunneling |
| socks5h:// | Remote (proxy server) | When DNS must be resolved through the proxy (Tor, restricted networks) |
Using socks5h:// is generally safer when you're unsure, as it ensures all traffic including DNS queries goes through the proxy.
### Proxy Authentication
If your SOCKS5 proxy requires authentication:
git config --global http.proxy socks5h://username:[email protected]:1080Note: Storing credentials in Git config is insecure. For sensitive environments, consider using a credential helper or environment variables.
### Debugging Proxy Connections
Enable curl verbose mode to see exactly what's happening:
GIT_CURL_VERBOSE=1 git clone https://github.com/user/repo.gitThis will show the proxy negotiation process and help identify where the connection fails.
### Common Proxy Software Setup
SSH Dynamic Tunnel:
# Create a SOCKS5 proxy through an SSH server
ssh -D 1080 -f -C -q -N [email protected]
# Then configure Git
git config --global http.proxy socks5h://127.0.0.1:1080Tor (for anonymity):
# Tor typically runs on port 9050
git config --global http.proxy socks5h://127.0.0.1:9050
# Or Tor Browser on port 9150
git config --global http.proxy socks5h://127.0.0.1:9150### NO_PROXY Configuration
To exclude certain hosts from proxy:
# Environment variable approach
export no_proxy="localhost,127.0.0.1,.local,.company.com"
# Git doesn't have a native no_proxy config, use domain-specific proxy instead
git config --global http.https://internal.company.com.proxy ""### Windows-Specific Notes
On Windows, proxy settings can also come from Internet Explorer/Edge settings. Git may pick these up through libcurl. To override:
# Explicitly disable system proxy
git config --global http.proxy ""### CI/CD Environments
In CI/CD pipelines, proxy settings often come from environment variables set by the runner:
# GitHub Actions example - clear proxy for direct connection
- name: Clear proxy settings
run: |
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY all_proxy
git config --global --unset http.proxy || true
git config --global --unset https.proxy || truekex_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