---
title: "Mac 上 Git 提示 Could not resolve host: github.com：修复方法 · Kilobat 指南"
url: "https://kilobat.app/zh-hans/guides/git-could-not-resolve-host-github.html"
description: "在 Mac 上执行 git clone 或 git push 时失败，提示 Could not resolve host: github.com。检查 DNS、代理和远程 URL，然后修复名称查询。"
---

错误信息

# Mac 上 Git 提示“Could not resolve host: github.com”

Git 无法获取 github.com 的地址。对于 HTTPS 远程仓库，Git 显示 curl 的消息；对于 SSH 远程仓库，ssh 显示它自己的消息。

适用于：macOS 或 Homebrew 安装的 Git，所有当前 macOS 版本。文字已在 Git 2.56 和 OpenSSH 10.5 上核对。 · 核查日期：2026年10月29日

## 症状

- Git 显示 `fatal: unable to access 'https://github.com/…/': Could not resolve host: github.com`。
- 使用 SSH 远程仓库时，ssh 显示 `Could not resolve hostname github.com: nodename nor servname provided, or not known`。
- `git clone`、`git pull` 和 `git push` 全部失败。

## 可能的原因

- **没有连接或没有 DNS。**Mac 无法查询任何名称。
- **Git 没有使用代理。**在需要代理的网络上，Git 需要 `http.proxy` 或代理环境变量。
- **VPN 或 DNS 过滤器。**VPN 的 DNS 服务器或过滤器可能没有对 github.com 作出应答。
- **远程 URL 错误。**远程地址中的拼写错误会得到一个不存在的名称。

## 如何检查

1. 显示仓库的远程 URL。

   ```
   git remote -v
   ```
2. 通过 macOS 解析器查询 github.com。

   ```
   dscacheutil -q host -a name github.com
   ```
3. 显示 Git 的代理设置和你的代理环境变量。

   ```
   git config --get http.proxy
   env | grep -i proxy
   ```
4. 用 curl 测试 HTTPS 路径。

   ```
   curl -I https://github.com
   ```

## 如何修复

1. 如果所有名称都查询失败，修复 DNS。参阅“[Mac 上 DNS 无法解析](https://kilobat.app/zh-hans/guides/dns-server-not-found.html)”。
2. 如果网络需要代理，为 Git 设置代理。

   ```
   git config --global http.proxy http://proxy.example.com:8080
   ```
3. 如果旧的代理设置有误，将其删除。

   ```
   git config --global --unset http.proxy
   ```
4. 如果远程 URL 有拼写错误，改正它。

   ```
   git remote set-url origin https://github.com/OWNER/REPO.git
   ```

## 使用 Kilobat

1. Kilobat 的连接诊断逐层测试主机：网络、代理、DNS、规则、IPv4、IPv6、TLS 和服务器，并指出失败的那一层。

   ```
   kilobat why github.com
   ```
2. Kilobat 的这些检查都是免费的。AI 智能体可以通过 MCP 用 `diagnose_connection` 和 `diagnose_network` 运行它们。请参阅[找出某个网站或 API 连不上的原因](https://kilobat.app/zh-hans/guides/recipes/why-cant-it-connect.html)。

## 常见问题

**GitHub 宕机了吗？**

有可能，但查询错误通常是本地问题。如果 `dscacheutil` 能查到其他名称却查不到 github.com，检查你的 DNS 或过滤器。

## 参考资料

- [curl：libcurl error codes](https://curl.se/libcurl/c/libcurl-errors.html)
- git-config(1)，http.proxy，macOS 27.2 自带的 man 手册页（Git 2.56）
- ssh(1) 和 dscacheutil(1)，macOS 27.2 自带的 man 手册页

参考资料核查于 2026年10月29日。man 手册页为 macOS 自带版本；在“终端”中用 `man <name>` 打开。

## 相关指南

- [Mac 上的“curl: (6) Could not resolve host”](https://kilobat.app/zh-hans/guides/curl-could-not-resolve-host.html): curl 退出码 6 表示 curl 无法获取主机名对应的地址。
- [Mac 上出现 ssh: connect to host port 22: Operation timed out](https://kilobat.app/zh-hans/guides/ssh-port-22-operation-timed-out.html): ssh 向端口 22 发送了连接请求，但没有收到应答。
- [Mac 上 SSH 和 Git 超时](https://kilobat.app/zh-hans/guides/ssh-git-timeouts.html): SSH 和 Git 需要与服务器之间有可用的 TCP 连接。
- [Mac 上 DNS 无法解析](https://kilobat.app/zh-hans/guides/dns-server-not-found.html): DNS 出故障时，Mac 无法把 apple.com 这样的名称转换成 IP 地址。
- [Mac 上公司代理证书导致“终端”工具出错](https://kilobat.app/zh-hans/guides/corporate-proxy-certificates.html): 一些公司网络会检查 HTTPS 流量。
