Operations 3 min read

Resolving Git Clone Connection Timeout on Windows by Adjusting SSH Config and Hosts File

The article walks through diagnosing and fixing a Git clone timeout on Windows by checking SSH connectivity, discovering DNS misresolution, and correcting the local hosts file to map github.com to its proper IP address, enabling successful repository cloning without a proxy.

Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Resolving Git Clone Connection Timeout on Windows by Adjusting SSH Config and Hosts File

Background: After switching to a Windows PC, the author encountered a timeout error when running git clone and could not make the connection work through environment variables or a proxy.

Detection: Using ssh -T [email protected] returned “ssh: connect to host github.com port 22: Connection timed out”. The author edited ~/.ssh/config to route GitHub through port 443:

Host github.com
    Hostname ssh.github.com
    Port 443

Even with port 443 the connection still timed out, prompting a suspicion that DNS resolution was failing.

DNS check: nslookup baidu.com returned normal addresses, but nslookup github.com returned the loopback address 127.0.0.1 , indicating a local DNS mapping problem.

Solution: The hosts file was edited (Windows path C:\Windows\System32\drivers\etc\hosts or macOS sudo vi /etc/hosts ) to add the correct GitHub IP:

140.82.113.4 github.com

After saving the hosts file, the author could access GitHub directly without a proxy and successfully run git clone .

Conclusion: Adjusting the local DNS hosts mapping resolves Git clone connection timeouts caused by incorrect DNS entries.

GitTroubleshootingwindowsDNSSSH
Rare Earth Juejin Tech Community
Written by

Rare Earth Juejin Tech Community

Juejin, a tech community that helps developers grow.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.