You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法克隆Github仓库:fatal: unable to access 错误排查与解决

解决Git克隆时"Could not resolve host: github.com"的问题

这个错误核心是终端无法解析github.com的DNS地址,还没到身份验证环节,所以和你配置的Git用户名、邮箱无关。以下是针对性解决步骤:

1. 先确认网络连通性

在终端执行ping github.com,如果输出显示unknown host github.com,直接坐实DNS解析问题。
可以用公共DNS测试,执行ping 8.8.8.8,如果能收到回复,说明本地DNS配置出错了。

2. 修改DNS服务器配置

针对WSL Ubuntu子系统:

  • 编辑DNS配置文件:sudo nano /etc/resolv.conf
  • 将文件内的nameserver行替换为公共DNS:
    nameserver 8.8.8.8
    nameserver 8.8.4.4
    
  • 按Ctrl+O保存,Ctrl+X退出编辑器,再尝试克隆命令。
  • 若重启WSL后配置被重置,创建/etc/wsl.conf文件锁定配置:
    sudo nano /etc/wsl.conf
    
    添加以下内容后保存并重启WSL(执行wsl --shutdown再重新打开终端):
    [network]
    generateResolvConf = false
    

针对Git Bash:

  • 找到Git安装目录下的resolv.conf文件,路径通常是C:\Program Files\Git\etc\resolv.conf
  • 用编辑器打开,替换nameserver为8.8.8.8和8.8.4.4,保存后重启Git Bash。

3. 检查并清理代理配置

如果你使用了代理,终端可能没正确适配代理规则:

  • 查看当前Git代理配置:
    git config --global --get http.proxy
    git config --global --get https.proxy
    
  • 若有输出,先临时取消代理再试:
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    
  • 确实需要代理的话,确保代理地址和端口正确,比如:
    git config --global http.proxy http://your-proxy-ip:port
    git config --global https.proxy https://your-proxy-ip:port
    

4. 用curl验证网络访问

执行curl https://github.com,如果能返回github的页面HTML内容,说明网络通路正常,再重新执行git clone命令即可。

内容的提问来源于stack exchange,提问作者Mer

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 11:03:16