Fix "Could not resolve host: github.com" โ€” Git Cannot Connect to Remote Repository

beginner๐Ÿ“ฆ Git2026-04-27| Linux, macOS, Windows โ€” Git 2.x, any shell (bash, zsh, PowerShell, CMD)

Error Message

fatal: unable to access 'https://github.com/user/repo.git/': Could not resolve host: github.com
#git#network#dns#proxy#https#remote

The Error

You run git clone, git pull, or git push and Git stops dead:

fatal: unable to access 'https://github.com/user/repo.git/': Could not resolve host: github.com

Git never even reaches the remote. No authentication prompt, no protocol handshake โ€” the connection fails at the DNS lookup stage. This is a network-layer problem, not a Git bug.

Diagnose First

Don't start tweaking settings blindly. Run these two checks first:

# Can your machine resolve github.com at all?
ping github.com

# Or use dig/nslookup for a clean DNS check
dig github.com
nslookup github.com

ping returning unknown host or nslookup showing no answer? DNS is broken โ€” go to Fix 1. Ping works but Git still fails? A proxy is almost certainly the culprit โ€” jump to Fix 2.

# Check if Git has a proxy configured
git config --global http.proxy
git config --global https.proxy

Fix 1 โ€” DNS Is Broken (Most Common)

Your machine can't translate github.com into an IP address. Switching to a public DNS resolver usually fixes this in under a minute.

Linux / macOS

# Edit /etc/resolv.conf and add a working nameserver
sudo nano /etc/resolv.conf

# Add one of these at the top:
nameserver 8.8.8.8
nameserver 1.1.1.1

On systems using systemd-resolved (Ubuntu 18.04+, Fedora, etc.), edits to resolv.conf won't survive a reboot. Use resolvectl instead:

sudo resolvectl dns eth0 8.8.8.8 1.1.1.1

Windows

# In PowerShell (run as Administrator)
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses 8.8.8.8,1.1.1.1

Prefer the GUI? Go to Network Settings โ†’ Change adapter options โ†’ IPv4 Properties and set the DNS server to 8.8.8.8.

Verify

ping github.com
# Should show: 64 bytes from 20.205.243.166 (or similar IP)

Fix 2 โ€” Git Proxy Is Wrong or Stale

Switched networks recently โ€” VPN on/off, office to home, hotel Wi-Fi? Git holds onto its proxy config indefinitely. It'll keep routing through a proxy that no longer exists until you clear it manually.

# Remove the proxy settings
git config --global --unset http.proxy
git config --global --unset https.proxy

# Confirm they're gone
git config --global --list | grep proxy

On a corporate network that genuinely requires a proxy, set it correctly:

git config --global http.proxy http://proxy.company.com:8080
git config --global https.proxy http://proxy.company.com:8080

Need it for one repo only, without touching global config?

git config http.proxy http://proxy.company.com:8080

Fix 3 โ€” Firewall Blocking Port 443

Test whether port 443 is actually reachable:

# Linux/macOS
curl -v https://github.com

# Windows
Test-NetConnection -ComputerName github.com -Port 443

Connection times out? A firewall or security appliance is dropping HTTPS traffic. Three ways out:

  • Ask your network admin to whitelist github.com on port 443
  • Hop onto a different network (mobile hotspot works well for a quick test)
  • Switch to SSH โ€” see Fix 5

Fix 4 โ€” Rogue /etc/hosts Entry

A single bad line in /etc/hosts can override DNS entirely, pointing github.com to 0.0.0.0 or some stale internal IP. Easy to check:

grep -i github /etc/hosts

Delete any line that redirects github.com to a local or invalid address. The file gets modified by GitHub Desktop and some VPN clients โ€” always review what's there before removing anything.

Fix 5 โ€” Switch to SSH Instead of HTTPS

HTTPS keeps getting blocked by your proxy or firewall? SSH often sidesteps the issue entirely. Port 22 and port 443 are filtered independently โ€” one being blocked doesn't mean the other is.

# Change your remote URL from HTTPS to SSH
git remote set-url origin git@github.com:user/repo.git

# Verify
git remote -v

You'll need an SSH key linked to your GitHub account. Generate one if you haven't:

ssh-keygen -t ed25519 -C "your@email.com"
cat ~/.ssh/id_ed25519.pub  # Copy this to GitHub โ†’ Settings โ†’ SSH Keys

# Test the connection
ssh -T git@github.com
# Expected: Hi username! You've successfully authenticated...

Fix 6 โ€” VPN Breaking Public DNS

Corporate VPNs are a common culprit. Many are configured to route only internal traffic through the tunnel while leaving public DNS resolution broken for external sites like github.com.

Quick test: disconnect the VPN and retry Git. Works immediately? The VPN config is the problem. A few options:

  • Ask IT whether split-tunnel is set up correctly for github.com
  • Add a static /etc/hosts entry using GitHub's current IP โ€” get it with dig github.com from a machine that's working
  • Switch to SSH (Fix 5), which sometimes routes differently through VPN tunnels

Verify the Fix

# Lightweight remote check โ€” no clone needed
git ls-remote https://github.com/user/repo.git

# Or clone a small public repo as a real-world test
git clone https://github.com/github/gitignore.git /tmp/test-clone

# Clean up after
rm -rf /tmp/test-clone

git ls-remote printing refs means the connection is fully working.

Tips

Debugging this in an environment with complex subnetting or VPNs? It helps to know what IP ranges are in play. I use the Subnet Calculator on ToolCraft to check CIDR ranges and verify whether GitHub's IP blocks (140.82.112.0/20 and others) fall within any restricted subnet. Runs entirely in the browser, nothing sent anywhere.

One permanent fix worth making: set your DNS to 8.8.8.8 or 1.1.1.1 at the router level rather than per-machine. Every device on the network benefits, and you won't chase this same issue after a reimage or new dev machine setup.

Related Error Notes