fatal: unable to access ‘https://github.com/…‘的解决办法
Git操作失败场景
原来项目中使用Git是正常的,无论是GitHub的项目还是码云的项目,都是可以正常pull和push的。但当将Mac Book的操作系统升级之后,发现Git无法执行pull和push操作,add和commit操作都还是正常的。
网络上的状况和解决方案
如果你不是因为升级操作系统导致的git失效,你可以先尝试一下网络上的解决方案。
场景一
在命令行执行以下命令:
git config --global --unset http.proxy git config --global --unset https.proxy
场景二
此方案主要针对,git clone时的问题。比如出现如下图的错误:

解决方案,第一查看git配置:
git config --global -l
第二,查看环境变量:
env|grep -i proxy
执行如下图所示:

场景三
问题状况:
git clone 遇到问题:fatal: unable to access ‘https://github.comxxxxxxxxxxx’: Failed to connect to xxxxxxxxxxxxx

解决方法:将命令行里的http改为git重新执行。

这个错误的原因主要是协议前缀写错了,导致git clone失败。
场景四
git的push和pull无法使用,状况如下图:

解决方案:先ping 代码仓库地址: ping gitlab.alibaba-inc.com
如果报错:

则找一台能ping的通的机器,看一下ping通后的ip地址是多少:

获得地址之后把ip地址和代码仓库地址加入本机hosts:

场景五
错误信息:fatal: unable to access ”: Could not resolve host: github.com – git clone失败。
使用git clone
命令时报错:
Cloning into 'GLACNet'... fatal: unable to access 'https://github.com/tkim-snu/GLACNet.git/': Could not resolve host: github.com
然后执行命令ping github.com
,也失败了:
ping: unknown host github.com
解决方案
修改/etc/hosts
文件:
sudo vim /etc/hosts
进入vim编辑该文件,在最后一行加入:
192.30.253.112 github.com
wq
保存退出,再使用 git 命令就可以了。注意,这里的ip地址可能为变化的,导致这个问题的主要原因就是无法正常访问GitHub官网。
场景六
最后,说一下我遇到的这种升级系统导致的比较特别的问题,由于是在Mac操作系统下,所在命令行中执行如下命令:
brew install git
重新install一下git问题便解决了。执行上述命令,如果卡在“Updating Homebrew…”界面,可以通过按一次control + c命令来阻断Homebrew的更新,直接进行上面命令的操作。
关注公众号:程序新视界,一个让你软实力、硬技术同步提升的平台
除非注明,否则均为程序新视界原创文章,转载必须以链接形式标明本文链接