我所做的:我在Github上创建了一个远程存储库,我试图在我的本地机器上克隆远程存储库。克隆时,我提供克隆URL和目标文件夹。

但每次我尝试克隆,我得到这个错误:

错误:“致命:无法访问https://github.com/hyperion057/spring-repo.git/':无法解决主机:github.com”

我需要做什么才能连接到GitHub ?


当前回答

我也犯过类似的错误。

C:\wamp\www\myrepository [master]> git push
fatal: unable to access 'https://github.com/myaccount/myrepository.git/': Couldn't resolve host 'github.com'

实际上,提示信息已经告诉我们哪里出错了。

https://github.com/myaccount/myrepository.git/

当我检查我的github,我发现我的github仓库的HTTPS url是

https://github.com/myaccount/myrepository.git

我不知道这是怎么回事。安装的Git Shell自动设置了错误的url。

一旦我删除了末尾的“/”,我就可以成功地推了。

其他回答

在通过https克隆git存储库时,我遇到了这个问题的另一个版本:

致命:无法访问'https://GIT_USER:GIT_PASSWORD@github.com/organization/repo.git/':无法解析主机:GIT_USER

问题是密码中有限制字符,需要进行URL编码。此外,如果您使用2FA(双因素身份验证),则应使用个人访问令牌来代替密码。

搜索上面的错误条件会在谷歌上找到这个页面,所以希望这个答案能节省一些人的时间。

如果你在Windows主机上使用wsl guest vm中的git,并连接到主机上的vpn来访问github,那么你可以在Windows主机配置中添加github的ip地址来临时解决这个问题。因为wsl2路由连接到vpn隧道有问题。 例如,在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

我需要配置代理设置吗?因为我办公室有代理服务器。

是的,您可以通过设置HTTP_PROXY和HTTPS_PROXY环境变量来做到这一点。

参见“同步与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

(为了避免在代理URL中明确放置您的凭据—用户名/密码,请参见下文)

注意NO_PROXY,允许访问您公司的内部站点

你也可以在你的git配置中注册:

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

但是如果你有不正确的代理Git设置,请删除它们:

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

不需要凭证:使用genotrance/px。 如果你像我一样,在一个NTLM代理背后的公司,你所需要做的就是:

解压缩px-v0.4.0.zip到任何你想要的地方 更改px.ini配置文件(把它放在%USERPROFILE%),更改服务器行: (代理) Server = proxy.my.company:8080 <=使用您公司的proxy:port Listen = 127.0.0.1 端口= 3128 使用HTTP(S)代理变量没有您的凭据!(px代理将通过Microsoft SSPI或Microsoft Kerberos重用当前寡妇会话中的文件)

这将给你:

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

Add

命名服务器8.8.8.8

在/etc/resolv.conf中重新启动

当你尝试上述解决方案,没有帮助,你可能需要检查你的本地网络设置,并尝试添加8.8.8.8和你的本地路由器ip到DNS字段。