The Nightmare Named “Connection timed out”
On a Monday morning, you’re sipping coffee and about to git clone a trending research library. Suddenly, a bright red line appears on your screen: Fatal: Failed to connect to github.com port 443: Timed out. After 30 seconds of waiting in vain, you realize you’ve been “flagged” by the corporate Firewall again.
The reason behind this firewall is actually quite simple. In high-security environments like banks or large corporations, all outbound Internet traffic must pass through an intermediary Proxy gateway. If you don’t declare a Proxy, Git will attempt to connect directly and will be immediately blocked by the Firewall.
I once lost an entire morning due to a silly mistake. After setting up a proxy to download code from GitHub, I completely forgot about it. When I needed to push code to the internal GitLab, Git “eagerly” pushed the traffic through the corporate proxy. As a result, the proxy couldn’t recognize the internal server, and everything froze.
Why You Shouldn’t Use a Global Proxy for Git?
The most common method found on StackOverflow is using the global configuration command:
git config --global http.proxy http://proxy-server:8080
This command solves the Internet access issue but causes a major headache. It applies this configuration to all repositories on your machine.
- With GitHub/GitLab.com: Runs smoothly.
- With internal GitLab (Intranet): Connection error because the Proxy cannot resolve IP addresses within the LAN.
Having to constantly unset and then set the proxy every time you switch projects is extremely frustrating. You need a smarter solution so Git knows exactly when it needs a Proxy “passport.”
Solution 1: Configure Proxy for Specific Domains (Recommended)
Git allows us to specify a Proxy based on the repository URL. This is the cleanest way to clone code from GitHub while working seamlessly with the company’s internal server.
Configuration for GitHub
Instead of using a generic global setting, explicitly specify that the https://github.com domain should go through the proxy:
git config --global http."https://github.com".proxy http://user:pass@proxy-server:8080
Configuration for GitLab or Bitbucket
You can apply the same logic to other platforms:
git config --global http."https://gitlab.com".proxy http://proxy-server:3128
With this method, Git only uses the Proxy when you interact with GitHub. When working with an internal server (e.g., https://git.company.com), Git will connect directly. Everything happens completely automatically.
Solution 2: Bypassing Barriers for SSH Connections
Many developers prefer using SSH ([email protected]:...) to avoid manual Token entry. However, note that the http.proxy configuration above has no effect on the SSH protocol.
To handle this, we need to modify the SSH config file at ~/.ssh/config.
On Linux or macOS (Using nc – netcat)
Open the ~/.ssh/config file and add the following snippet:
Host github.com
HostName github.com
User git
# Use for HTTP Proxy
ProxyCommand nc -X connect -x proxy-server:8080 %h %p
On Windows (Using connect.exe)
Git Bash on Windows comes with a powerful tool called connect.exe. Your configuration will look like this:
Host github.com
HostName github.com
User git
ProxyCommand connect -H proxy-server:8080 %h %p
If the proxy requires authentication, simply add the credentials before the server address: connect -H user:pass@proxy-server:8080.
Solution 3: Environment Variables (For Emergency Situations)
If you only need to use a Proxy once to quickly clone a project, don’t bother changing the config. Use environment variables directly in the command line.
# Linux/macOS
HTTPS_PROXY=http://proxy-server:8080 git clone https://github.com/user/repo.git
# Windows (PowerShell)
$env:HTTPS_PROXY="http://proxy-server:8080"; git clone https://github.com/user/repo.git
# Or command prompt
set HTTPS_PROXY=http://proxy-server:8080 & git clone https://github.com/user/repo.git
This method is extremely useful when debugging on a temporary server and you don’t want to leave any configuration traces.
Real-world Experience: Handling NTLM Proxy (Windows Authentication)
In corporate environments using NTLM, Git often throws a 407 error (Proxy Authentication Required) even if the password is correct. Git isn’t naturally great at handling Windows-specific authentication protocols.
The optimal solution is to install Cntlm. This tool acts as an intermediary proxy running at 127.0.0.1:3128. It handles the complex “handshake” with the corporate proxy. Then, you just need to point Git to your local machine:
git config --global http.proxy http://127.0.0.1:3128
Cntlm is not only a lifesaver for Git but also for NPM, Docker, and Pip.
How to Check and Clean Up Configuration
When you take your laptop to a cafe or home, old proxy configurations can cause Git errors. Check your active rules using the command:
git config --global --get-regexp proxy
If you want to completely remove them and return to defaults:
# Remove proxy for a specific domain
git config --global --unset http."https://github.com".proxy
# Remove the entire global proxy
git config --global --unset http.proxy
Conclusion
Mastering Proxy configurations makes you more professional and saves hours of wasted time. My advice is to prioritize Solution 1 to clearly separate traffic. Don’t forget that git config --list is always your best friend whenever you encounter connection issues. Good luck with your setup!

