[Git/GitHub] Error: fatal: unable to access 'https://github.com/...': Could not resolve host — Network or DNS issue
Summary
fatal: unable to access 'https://github.com/...': Could not resolve host occurs when Git cannot reach the remote server (e.g., GitHub) due to a network, DNS, or proxy misconfiguration. The system fails to translate the domain name into an IP address, preventing Git from establishing a connection.
Context
This error often appears in restricted or misconfigured network environments — such as corporate proxies, VPNs, or when DNS caching fails. Git relies on the same networking stack as curl, so any connectivity or resolution issue at the system level will propagate to Git commands.
Probable Cause
- No internet access or unstable network.
- DNS server failed to resolve
github.com. - Firewall, proxy, or VPN blocking HTTPS connections.
- Incorrect remote URL (e.g., typo or missing
.gitsuffix). - Temporary GitHub outage or regional restriction.
Quick Fix
- Verify internet access:
# Open GitHub in browser https://github.com/ - Check remote URL:
git remote -vCorrect typos using:
git remote set-url origin https://github.com/username/repo.git - Ping GitHub:
ping github.comIf it fails, it’s likely a DNS or network issue.
- Check or reset proxy configuration:
# If using a proxy git config --global http.proxy http://user:password@proxy:port # To remove proxy settings git config --global --unset http.proxy - Flush DNS cache:
- Windows:
ipconfig /flushdns - macOS:
sudo dscacheutil -flushcache - Linux:
sudo systemd-resolve --flush-caches
- Windows:
- Retry Git command:
git fetch git pull git push
Example
# Error
$ git push origin main
fatal: unable to access 'https://github.com/username/repo.git/': Could not resolve host: github.com
# Fix
$ ping github.com
# -> no response
$ ipconfig /flushdns
$ git push origin main
# -> success
Alternate Scenarios
- Corporate networks: Git traffic blocked by proxy — configure
http.proxyor use SSH instead of HTTPS. - VPN interference: Disconnect or reconnect to update DNS routes.
- Temporary GitHub outage: Test on GitHub Status before making changes locally.
Pitfalls & Debug
- Symptom → “curl: (6) Could not resolve host.” Fix → DNS failure — restart resolver or use a public DNS (e.g., 8.8.8.8).
- Symptom → Works in browser but fails in Git.
Fix → Remove outdated Git proxy settings:
git config --global --unset http.proxy. - Symptom → Works on one machine but not another. Fix → Compare DNS settings or /etc/hosts entries between systems.
Verification & Next Steps
# Confirm remote URL
git remote show origin
# Test DNS resolution
nslookup github.com
dig github.com
# Try SSH alternative
git remote set-url origin git@github.com:username/repo.git
Best Practices
- Use stable DNS servers (e.g., Cloudflare 1.1.1.1, Google 8.8.8.8).
- Avoid corporate proxies unless configured correctly.
- Prefer SSH authentication for long-term reliability.
- Regularly flush DNS cache on laptops that switch between networks.
Sources
Stack Overflow — Could not resolve host
Tool/Git, OS/Cross-platform, Topic/Network Connectivity