Ever struggled with cloning Git repositories behind a proxy? Here’s how to fix it!
table of contents
Open table of contents
Problem: Failed to Connect to GitHub via HTTPS
When attempting to clone a repository, you might encounter connection errors like:
fatal: unable to access 'https://github.com/...': Failed to connect to github.com port 443
This often occurs in restricted network environments (e.g., corporate networks) where direct access to GitHub is blocked.
Step-by-Step Solution
1. Check Current Proxy Settings
First, verify if Git is using any existing proxy configurations:
git config --global --get http.proxy
git config --global --get https.proxy
If no proxy is set, these commands return empty results.
2. Configure HTTP/HTTPS Proxy (Common Pitfall)
Many guides suggest setting an HTTP proxy:
git config --global http.proxy http://127.0.0.1:10808
git config --global https.proxy https://127.0.0.1:10808
Result:
fatal: Proxy CONNECT aborted # Indicates protocol mismatch or invalid proxy type
3. Switch to SOCKS Proxy (The Fix)
If you’re using a SOCKS5 proxy (e.g., Shadowsocks, VPN tools), configure Git accordingly:
git config --global http.proxy "socks5://127.0.0.1:10808"
git config --global https.proxy "socks5://127.0.0.1:10808"
Retry cloning:
git clone https://github.com/paulik123/django-htmx-crud-demo.git
Success! The repository now clones without errors.
Why This Works
- HTTP vs. SOCKS Proxies:
- HTTP proxies handle HTTP/HTTPS traffic but may fail with non-web protocols.
- SOCKS proxies operate at the TCP layer, making them ideal for Git’s operations.
- Port 10808: Common default port for SOCKS5 proxies (adjust if yours differs).
Troubleshooting Tips
- Verify Proxy Tools: Ensure your proxy client (e.g., Shadowsocks) is running.
- Check Firewall Rules: Allow Git and your proxy tool through the firewall.
- Test Direct Connection:
curl -v https://github.com # Diagnose network issues
Reverting Proxy Settings
To reset configurations:
git config --global --unset http.proxy
git config --global --unset https.proxy
Conclusion
Proxy issues can be frustrating, but understanding your network setup and proxy type is key. By configuring Git to use a SOCKS5 proxy instead of HTTP, you bypass restrictive network policies and enable seamless repository access.