'Git: Could not resolve host github.com error while cloning remote repository in git
What I did: I have created a remote repository on Github and I am trying to clone the remote repository on my local machine. While cloning I am providing the clone URL & target folder.
But every time I try to clone, I am getting this error:
Error: "fatal: unable to access 'https://github.com/hyperion057/spring-repo.git/': Could not resolve host: github.com"
What do I need to do to connect to GitHub ?
Solution 1:[1]
I got a similar error, and it's caused by incorrect proxy setting. This command saved me:
git config --global --unset http.proxy
https version:
git config --global --unset https.proxy
Solution 2:[2]
Spent a couple hours trying to fix this.
Re-connecting my wifi did the trick.
Solution 3:[3]
another possibility, I ran into this problem myself. But it was after I had installed a VPN (which was unrelated and running)
turning off the VPN, fixed the issue.
for the record, I was running "Viscosity" VPN on my MacBookPro
Solution 4:[4]
I've had the same issue after running out of disk space. Closing and reopening terminal fixed it one time. Restarting my Mac the next.
Some easy things to try before jumping to random commands:
- restart terminal tab
- restart terminal app
- If disk is full (or close to it) free up some disk space then restart terminal app
- restart machine/OS
Solution 5:[5]
Would like to note, when I did Brian's solution:
git config --global --unset http.proxy
Make sure to quit and restart terminal. Mine didn't resolve until I did that.
Solution 6:[6]
192.30.252.128 is the current IP of github.com which can be set in your local DNS (/etc/hosts in Linux and C:\Windows\System32\drivers\etc\hosts)
Solution 7:[7]
From the answer here -> my solution is specific for Windows Subsystem for Linux (WSL) users. None of the answers relating to proxies are relevant to my solution.
If you are unable to run a ping command e.g.
# WSL
ping google.com
Then it is likely your file at /etc/resolve.conf is corrupt. To fix this run the following in a WSL window:
# WSL
sudo rm /etc/resolve.conf
Then open a Powershell terminal in Administrator mode and run
# Powershell
wsl --shutdown
Get-Service LxssManager | Restart-Service
This should fix the problem, which can be tested by running the ping command again.
Solution 8:[8]
I solved it by using this command
$git config --global http.proxy http://enter_your_proxy:enter_port
Solution 9:[9]
In my case, on a Windows box, my TCP/IP stack seems to have needed to be reset. Resetting the TCP/IP stack of the client PC caused git to start behaving properly again. Run this command in Administrator mode at a command prompt and retry the git command:
netsh int ip reset
Manually disabling and re-enabling the network adapter via the Control Panel produces a similar result.
I suspect DNS resolution problems inside the TCP stack on my Windows box.
Solution 10:[10]
When you tried above solutions and nothing helps, you may need to checkout your local network settings and try to add 8.8.8.8 and your local router ip to the DNS filed.
Solution 11:[11]
I had this very similar error as following.
C:\wamp\www\myrepository [master]> git push
fatal: unable to access 'https://github.com/myaccount/myrepository.git/': Couldn't resolve host 'github.com'
Actually, the prompt message has told us where's wrong.
https://github.com/myaccount/myrepository.git/
When I check my github, I found my github repository's HTTPS url is
https://github.com/myaccount/myrepository.git
I don't know how this happened. The wrong url has been set up by installed Git Shell automatically.
Once I remove the '/' at the end, I can push successfully.
Solution 12:[12]
All, I want to let you all know that I was having this same issue. I solve it by resetting my remote URL git remote set-url origin https://new.url.here I found how to do this from this answer but I had to change hit to https: Change the URI (URL) for a remote Git repository
Solution 13:[13]
Just in case future generations stuck in this too: For me what worked (on mac OSX) was to set my DNS with opendns 208.67.222.222 , 208.67.220.220. I get this numbers here: https://www.opendns.com. For some reason, my dns configuration reseted to the default numbers (my local ip I guess), and I was not able to connect to neither github, brew or rubygems. Sorry for the misspelling.
Solution 14:[14]
Edge case here but I tried (almost) all of the above answers above on VirtualBox and nothing was doing it but then closing not only the VirtualBoxVM but good ole VirtualBox itself and restarting the program itself did the trick without 0 complaint.
Hope that can help ~0.1% of queriers : )
Solution 15:[15]
If you have a VPN needed to connect to your enterprise account and do a "git pull" this error will occur, just switch on your VPN and it will work.
Solution 16:[16]
Maybe it is because of your internet access, You can try:
ping google.com
If you get this error again, there was problem in your network configuration.
Solution 17:[17]
After restart git bash below works fine for me:
git push -f origin master
Solution 18:[18]
As a suggestion for Ubuntu servers, you can write down essid and password of router in your /etc/network/interfaces file:
iface [en0 || your wireless driver no necessarily en0] inet static
address 192.168.1.100 / (something for your static ip between 1-255)
netmask 255.255.255.0
gateway 192.168.1.1 / (this is the ip of your router)
dns-nameservers 8.8.8.8 / (you can use whatever you want)
wpa-ssid qwertyuio / (this is router id)
wpa-psk qwertyuio / (this is router password for wireless connection)
When I got this error while pulling a repository to my server, I wrote wpa-ssid and wpa-psk and restarted. Then it worked.
EDIT: I faced the same issue again and this time it was because of the inconsistency in router signal levels. My connection was not strong, that was the problem. However, the solution above is a real solution for static ip
Solution 19:[19]
One reason for this issue could be wrong/empty /etc/resolv.conf file.
The way I resolved this issue in my centos 7 minimal is as follows:
my /etc/resolv.conf was empty and I added the following lines:
nameserver 192.168.1.1
nameserver 0.0.0.0
where 192.168.1.1 is my gateway, in your case it can be different.
Solution 20:[20]
In my case I open a new terminal and problem solved. I don't know exactly what caused the problem in the first place though.
Solution 21:[21]
After clearing the Empty cache and hard reload from the Chrome dev tool of https://github.com/ thats works for me.
Open your Chrome dev tool and right click on reload icon, then you can see this option.
Solution 22:[22]
the simple solution to removing extra "/" from git clone remote is putting the url in parentheses. git clone " "
Solution 23:[23]
Different from all these solutions, in my case, I solved the issue when I restarted my terminal (or open another window).
Solution 24:[24]
Restarting terminal in Mac worked.
Solution 25:[25]
I guess my case was very rare, but GitHub was out down. Check their webpage to see if it loads properly.
Solution 26:[26]
I faced a different version of this problem while cloning the git repository via https:
fatal: unable to access 'https://GIT_USER:[email protected]/organization/repo.git/': Could not resolve host: GIT_USER
The problem was there were restricted characters in the password and it needs to be URL encoded. Additionally, if you are using 2FA (two factor authentication) then personal access token should be used in place of the password.
Searching the error condition above yields this page on google, so hopefully this answer will save someones time.
Solution 27:[27]
For Windows user using TortoiseGit, see Settings-Network, and enter proxy settings directly there. Easiest fix I've had to do all year.
Solution 28:[28]
I ran command on terminal, then restarted terminal.
git config --global --unset https.proxy
But it din't work. Then I turned Off and On my wifi on Mac.
git push
It worked.
Solution 29:[29]
In case your proxy server doesn't have username and password -
Change it like this-
192.168.49.1:8282 - <your-proxy-ip>:<port>
git config ---global http.proxy 192.168.49.1:8282
git config ---global https.proxy 192.168.49.1:8282
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow

