HyperioN
HyperioN

Reputation: 3928

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 ?

Upvotes: 336

Views: 920676

Answers (30)

Yusril Maulidan Raji
Yusril Maulidan Raji

Reputation: 1942

In my case, restarting my PC solved it immediately.

Upvotes: 2

Laura Corssac
Laura Corssac

Reputation: 1377

I guess my case was very rare, but GitHub was out down. Check their webpage to see if it loads properly.

Upvotes: 0

radsdau
radsdau

Reputation: 501

For Windows user using TortoiseGit, see Settings-Network, and enter proxy settings directly there.

Upvotes: 0

Mehreen
Mehreen

Reputation: 19

Add

nameserver 8.8.8.8

in /etc/resolv.conf and restart

Upvotes: 1

Lalith Yagnavalkya
Lalith Yagnavalkya

Reputation: 159

enter image description here

I fixed this issue by using this command

git init

enter image description here

Upvotes: 2

Kushagra Kumar
Kushagra Kumar

Reputation: 191

Restarting my EC2 instance fixed the issue.

Upvotes: 4

Egorrishe
Egorrishe

Reputation: 48

In my case problem was due to "Transfer ownership" of project to another Git user. When you do it, project URL changes from:

https://github.com/USER_1/repository.git to: https://github.com/USER_2/repository.git

Nevertheless it, project still accessible via old URL - so you can pull/push commits, without changing config. But, after ~1 year this URL become unreachable.

Solution:

  1. git remote -v - to see remotes
  2. git remote set-url origin https://github.com/USER_2/repository.git
  • next time change config immediately, and on ALL your computers 🤦‍♂️😁

Upvotes: 1

Josheir
Josheir

Reputation: 29

In my case, Visual Code hadn't installed the GitHub extension.

Upvotes: 0

botana_dev
botana_dev

Reputation: 538

In my specific case, there's a software called ZScaler that was blocking access to the internet. Restarting it fixed it. I suppose you need to try to restart your PC before setting proxies and all the other stuff, as the nature of the problem might be simpler than you think. Sometimes it is just no access to the internet.

Upvotes: 1

jxn
jxn

Reputation: 846

I was able to fix this by unplugging my ethernet cable and plugging it back in. A reboot would probably work too, but this was the only way I could resolve it. The next thing I was going to try was a reboot.

Upvotes: -1

Yufeng Lan
Yufeng Lan

Reputation: 49

If you are using git from wsl guest vm on Windows host, and connected to a vpn on host to access github, then you may add github's ip address to windows host configuration to temporarily solve this problem. Because wsl2 has problem routing connection to vpn tunnel. Example, add following lines to C:\Windows\System32\drivers\etc\hosts

# used from wsl, need update periodically
20.205.243.166  github.com
20.205.243.168  api.github.com

Upvotes: 1

nurmdrafi
nurmdrafi

Reputation: 529

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.

enter image description here

Upvotes: 1

Nazmul Hoque
Nazmul Hoque

Reputation: 970

After restart git bash below works fine for me:

git push -f origin master

Upvotes: 3

Hacker--Rohan Raj
Hacker--Rohan Raj

Reputation: 79

Simply enter this command in your kali linux terminal before cloning repository:-

service NetworkManager start

Upvotes: 1

Azedin derkawski
Azedin derkawski

Reputation: 67

I had the same message and later I found out that the issue was that I was not connected to the VPN where the remote repo is...

Upvotes: 0

Ankit Bhardwaj
Ankit Bhardwaj

Reputation: 141

I solved it by using this command

$git config --global http.proxy http://enter_your_proxy:enter_port

Upvotes: 12

Ayush ShaZz
Ayush ShaZz

Reputation: 346

It worked for me when I used

service apache2 stop

Upvotes: 0

Naser Nikzad
Naser Nikzad

Reputation: 951

In my case (which was a private repo of git), host was suspended, so the issue was with my GitHub server and the administrator resolved it.

Upvotes: 0

Lone Ronin
Lone Ronin

Reputation: 2910

If all the above answers failed to solve your problem, try rebooting the router.

Upvotes: 1

agrippa
agrippa

Reputation: 909

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.

Upvotes: 55

Piyush
Piyush

Reputation: 813

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

Upvotes: 1

d-man
d-man

Reputation: 496

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.

Upvotes: 13

M.Yessir
M.Yessir

Reputation: 222

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.

Upvotes: 3

Emin
Emin

Reputation: 113

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.

Upvotes: 0

yasi
yasi

Reputation: 547

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.

Upvotes: 10

VonC
VonC

Reputation: 1328282

do i need to configure proxy settings? because my office has got proxy servers.

Yes, you can do so by setting HTTP_PROXY, and HTTPS_PROXY environment variables.

See "Syncing with github":

set HTTPS_PROXY=http://<login_internet>:<password_internet>@aproxy:aport
set HTTP_PROXY=http://<login_internet>:<password_internet>@aproxy:aport
set NO_PROXY=localhost,my.company

(To avoid putting your credentials -- username/password -- in clear in the proxy URL, see below)

Note the NO_PROXY, to allow to access internal site to your company

You also can register that in your git config:

git config --global http.proxy http://<login_internet>:<password_internet>@aproxy:aport

But if you have incorrect proxy Git settings, remove them:

cd /path/to/repo
git config --unset http.proxy
git config --global --unset http.proxy
git config --system --unset http.proxy

git config --unset https.proxy
git config --global --unset https.proxy
git config --system --unset https.proxy

# double-check with:
git config -l --show-origin | grep -i proxy

No credentials needed: use genotrance/px.
If you are, as I am, in a company behind a NTLM proxy, all you need to do is:

  • unzip px-v0.4.0.zip anywhere you want
  • change the px.ini config file (put it in %USERPROFILE%), chaging the server line:
    [proxy]
    server = proxy.my.company:8080  <= use your company proxy:port
    listen = 127.0.0.1
    port = 3128
    
  • use HTTP(S) proxy variable without your credentials! (the px proxy will reuse the ones from the current Widows session, either through Microsoft SSPI or Microsoft Kerberos)

That will give you:

set HTTPS_PROXY=http://127.0.0.1:3128
set HTTP_PROXY=http://127.0.0.1:3128
set NO_PROXY=localhost,my.company

Upvotes: 129

Zack117
Zack117

Reputation: 1075

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.

Upvotes: 2

user3814933
user3814933

Reputation: 41

Restarting terminal in Mac worked.

Upvotes: 2

tong
tong

Reputation: 731

Different from all these solutions, in my case, I solved the issue when I restarted my terminal (or open another window).

Upvotes: 0

scosman
scosman

Reputation: 2593

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

Upvotes: 43

Related Questions