git 出现错误 Could not resolve host: github.com

今天早上push项目到远程仓库的时候,突然出现这个错误:

Could not resolve host: github.com

经查询,原来是github.com没有被主机解析
可通过以下方法解决

  1. 打开终端,输入以下命令
ping github.com

结果如下图


git 出现错误 Could not resolve host: github.com_第1张图片
github ip地址
  1. 退出ping命令,编辑文件etc/hosts,执行命令
sudo vi /etc/hosts

i 启动编辑模式,然后添加github的地址

# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost
255.255.255.255 broadcasthost
192.30.255.112  github.com  //github地址
::1             localhost
fe80::1%lo0     localhost

esc
:wq 退出即可

你可能感兴趣的:(git 出现错误 Could not resolve host: github.com)