Could Not Resolve Host github.com: What It Means and How to Fix It
If you've ever run a git clone, git pull, or git push command and hit back the error "could not resolve host: github.com", you're dealing with a DNS or network connectivity problem β not a GitHub outage, and not a broken Git installation. Understanding what's actually failing makes the fix much easier to find.
What "Could Not Resolve Host" Actually Means
When Git tries to connect to github.com, it first needs to translate that human-readable domain name into an IP address. That translation is handled by the Domain Name System (DNS). "Could not resolve host" means the DNS lookup failed β your machine asked "what's the IP address for github.com?" and got no usable answer back.
The error looks something like this:
fatal: unable to access 'https://github.com/user/repo.git/': Could not resolve host: github.com This is a network-layer problem, sitting below Git itself. Git is working fine. The issue is between your machine and DNS resolution.
Common Causes of the Error
Several different conditions can produce the same error message, which is why the fix isn't always the same.
π No Active Internet Connection
The most obvious cause. If your machine is offline or only partially connected (connected to a router but not the internet), DNS queries fail entirely. Check with a browser first β if websites aren't loading, start there.
DNS Server Problems
Your machine is configured to use a specific DNS server β usually assigned automatically by your router or ISP. If that server is:
- Temporarily unreachable
- Returning incorrect results
- Blocking certain domains (common on corporate or school networks)
β¦then the resolution fails even with a working internet connection.
Proxy and Firewall Interference
Corporate environments frequently route traffic through HTTP/HTTPS proxies. If Git isn't configured to use the same proxy your browser uses, Git's requests go nowhere. Similarly, overly aggressive firewalls can silently block DNS queries or HTTPS traffic to specific hosts.
Git Proxy Misconfiguration
Sometimes the problem is the opposite: Git is configured to use a proxy β one that no longer exists, has changed addresses, or isn't running. A stale proxy setting in your Git config will cause this error on a network where no proxy is needed.
Check your Git proxy config with:
git config --global --get http.proxy git config --global --get https.proxy If there's a value there that shouldn't be, remove it with:
git config --global --unset http.proxy git config --global --unset https.proxy /etc/hosts or DNS Cache Issues
On Linux and macOS, the /etc/hosts file is checked before DNS. A misconfigured entry pointing github.com at the wrong IP (or blocking it) will break resolution silently. On Windows, the equivalent is C:WindowsSystem32driversetchosts.
A stale DNS cache can also be the culprit, especially after network changes. Flushing it is a low-risk step worth trying early.
| OS | Flush DNS Command |
|---|---|
| Windows | ipconfig /flushdns |
| macOS | sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder |
| Linux (systemd) | sudo systemd-resolve --flush-caches |
Diagnostic Steps to Narrow It Down
Before changing anything, confirm where the failure actually is.
Test DNS resolution directly:
nslookup github.com # or dig github.com If these return an IP address, DNS is working and the issue is something else (possibly SSH key configuration or a proxy). If they return an error or time out, DNS resolution is confirmed broken.
Test basic connectivity:
ping github.com If ping works but Git doesn't, the problem is likely Git-specific (proxy settings, protocol mismatch, or credential issues rather than DNS).
Switching DNS Servers
If your assigned DNS server is the problem, switching to a public alternative is a straightforward fix. Google (8.8.8.8) and Cloudflare (1.1.1.1) are commonly used alternatives. This change is made at the operating system network settings level, not inside Git.
On networks where the DNS server is intentionally filtering traffic, switching servers may not help β the filtering may happen upstream of DNS.
SSH vs HTTPS Protocol
If you're using HTTPS URLs (starting with https://) and hitting this error, switching to SSH-based URLs (starting with [email protected]) can sometimes route around the problem, since they use a different protocol path (port 22 vs port 443). This only works if SSH isn't also blocked and you have an SSH key configured with GitHub.
Variables That Determine Which Fix Works π§
The same error message can stem from meaningfully different problems depending on your setup:
- Network environment: Home networks, corporate networks, and public Wi-Fi all behave differently. Corporate networks are far more likely to involve proxy requirements or DNS filtering.
- Operating system: DNS flushing, hosts file location, and proxy configuration all vary across Windows, macOS, and Linux distributions.
- Git version and configuration: Older Git versions handle proxy and SSL configuration differently than newer ones.
- Protocol in use: Whether your remote URLs use HTTPS or SSH affects which network paths and ports are involved.
- VPN status: VPNs often override DNS settings entirely β connecting or disconnecting one can cause or cure this error depending on configuration.
What resolves the error for someone on a home macOS machine using HTTPS may not apply at all to someone on a Linux workstation inside a corporate proxy environment. The diagnostic output from nslookup and your Git config is where the actual answer lives for your specific situation.