Git: Could not resolve host github.com error while cloning remote repository in git
Asked Answered
K

43

318

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 ?

Kaifeng answered 4/12, 2013 at 8:17 Comment(8)
What command are you using? Are you cloning by https or ssh? I just tried to clone your project and it worked.Immiscible
I am using git GUI and i'm cloning by HTTPS.Kaifeng
Open a terminal and execute git clone [email protected]:hyperion057/spring-repo.gitImmiscible
Now i am getting error- ssh: github.com:no address associated with name fatal: Could not read from remote repositoryKaifeng
do i need to configure proxy settings? because my office has got proxy servers.Kaifeng
The errors you are getting are basically telling you it cannot connect. You have probably set your proxy to the browser, but not on the entire machine. Try to set the proxy accordingly and try again.Immiscible
Its working now i needed to configure proxy settings! Thanks anywaysKaifeng
Please try to restart your router and PC. I'm not under a proxy and this worked for me.Minim
W
128

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
Wall answered 4/12, 2013 at 9:43 Comment(2)
what are the <login_internet> and <password_internet>?Janie
@Janie The login/password of your Windows session when you are using an enterprise proxy.Wall
B
404

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
Brannen answered 3/2, 2015 at 16:5 Comment(2)
This is worth trying even if you never touched the proxy setting and aren't behind one currently. I think this was somehow set automatically during a past hotel stay (or when using in-flight wifi) where a proxy was in place.Karee
Note that this will only unset the HTTP proxy. If you're having difficulty connecting to HTTPS locations, use the sister command 'git config --global --unset https.proxy'Turkic
A
236

Spent a couple hours trying to fix this.

Re-connecting my wifi did the trick.

Assizes answered 13/1, 2016 at 22:2 Comment(1)
This fixed my problem. What is the reason why this fixes it?Meri
W
128

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
Wall answered 4/12, 2013 at 9:43 Comment(2)
what are the <login_internet> and <password_internet>?Janie
@Janie The login/password of your Windows session when you are using an enterprise proxy.Wall
U
58

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

Unused answered 19/1, 2014 at 19:47 Comment(1)
heh, for me it's the other way around. github.com resolves only when I'm on VPN. :|Glib
D
52

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.

Drabble answered 26/1, 2017 at 22:58 Comment(0)
H
43

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
Hankering answered 21/10, 2016 at 12:29 Comment(1)
Just closing a terminal tab is sufficient as well.Lief
D
23

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)

Debrahdebrecen answered 29/12, 2014 at 19:37 Comment(1)
Current IP Addresses are listed here: api.github.com/meta (from help.github.com/articles/about-github-s-ip-addresses) and here is a tool to convert CIDR to ip range : ipaddressguide.com/cidrCostrel
C
12

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.

Complexity answered 7/8, 2021 at 11:2 Comment(0)
M
11

I solved it by using this command

$git config --global http.proxy http://enter_your_proxy:enter_port
Marilou answered 10/5, 2016 at 6:54 Comment(0)
K
9

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.

Koumis answered 6/1, 2021 at 15:13 Comment(0)
C
4

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.

Citystate answered 25/4, 2015 at 2:48 Comment(0)
L
3

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.

Lengthy answered 13/11, 2015 at 4:37 Comment(0)
P
3

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.

Poulterer answered 27/1, 2016 at 0:1 Comment(1)
git remote -v to see the remotes. git remote set-url origin https://github.com/USERNAME/REPOSITORY.git to set the remote.Iced
B
3

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 : )

Birdsong answered 7/3, 2017 at 2:20 Comment(0)
C
3

Restarting my EC2 instance fixed the issue.

Cay answered 9/5, 2023 at 2:17 Comment(0)
V
2

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

Vinic answered 16/5, 2014 at 22:19 Comment(0)
G
2

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.

Gardol answered 3/2, 2016 at 4:59 Comment(0)
S
2

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.

Sussex answered 23/4, 2017 at 13:1 Comment(1)
after adding nameserver 8.8.8.8, it working for me and able to clone git repoOrban
I
2

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.

Incarnadine answered 7/8, 2020 at 14:46 Comment(0)
P
2

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.

Pisano answered 29/7, 2021 at 12:51 Comment(0)
I
2

After restart git bash below works fine for me:

git push -f origin master
Inutile answered 29/9, 2021 at 4:57 Comment(0)
L
1

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

Lizzettelizzie answered 9/12, 2016 at 17:16 Comment(0)
N
1

the simple solution to removing extra "/" from git clone remote is putting the url in parentheses. git clone " "

Noneffective answered 15/6, 2017 at 5:50 Comment(0)
K
1

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.

Kinesthesia answered 7/2, 2018 at 19:58 Comment(0)
D
1

Restarting terminal in Mac worked.

Diplo answered 18/12, 2019 at 14:12 Comment(0)
C
1

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

Chemosh answered 7/3, 2020 at 21:5 Comment(0)
M
1

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
Minnich answered 27/10, 2021 at 3:13 Comment(0)
C
1

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

service NetworkManager start
Czechoslovak answered 27/12, 2021 at 8:22 Comment(0)
P
1

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

Prepossess answered 19/3, 2022 at 6:18 Comment(0)
I
1

Add

nameserver 8.8.8.8

in /etc/resolv.conf and restart

Imperforate answered 12/5, 2022 at 9:58 Comment(0)
R
1

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
Rob answered 4/6, 2022 at 14:23 Comment(0)
N
1

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.

Nore answered 10/1, 2023 at 15:28 Comment(0)
B
1

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 🤦‍♂️😁
Braces answered 27/4, 2023 at 13:18 Comment(0)
T
1

enter image description here

I fixed this issue by using this command

git init

enter image description here

Tseng answered 9/10, 2023 at 11:30 Comment(0)
A
0

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

Alberto answered 11/2, 2019 at 10:6 Comment(0)
W
0

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.

Wrongdoer answered 29/4, 2020 at 4:3 Comment(0)
C
0

It worked for me when I used

service apache2 stop
Catarinacatarrh answered 8/6, 2020 at 19:56 Comment(1)
Please edit the answer to include an explanation of why stopping the apache webserver would impact the ability to clone a git repo. There is also no mention here about starting the webserver back up after cloning, so this answer could be considered dangerous advice for someone who was unfamiliar and tried it.Janellejanene
S
0

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

GitHub

Schramm answered 22/6, 2020 at 20:5 Comment(0)
D
0

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.

Divider answered 6/3, 2021 at 19:12 Comment(0)
A
0

For Windows user using TortoiseGit, see Settings-Network, and enter proxy settings directly there. Easiest fix I've had to do all year.

Ancalin answered 7/5, 2021 at 4:42 Comment(0)
C
0

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...

Conventioner answered 1/12, 2021 at 12:55 Comment(0)
K
0

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

Karame answered 21/2, 2023 at 19:53 Comment(0)
P
-1

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.

Partake answered 24/10, 2022 at 16:6 Comment(1)
Who knows, prolly works for all cases :D In my case it was some DNS problem, so flushdns did the trick, but ur method might've just worked too.Rakel

© 2022 - 2024 — McMap. All rights reserved.