---
title: "Mac 上 Git 出現 Could not resolve host: github.com：修正方法 · Kilobat 指南"
url: "https://kilobat.app/zh-hant/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-hant/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-hant/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-hant/guides/curl-could-not-resolve-host.html): curl 結束代碼 6 表示 curl 無法取得主機名稱的位址。
- [Mac 上的 ssh: connect to host port 22: Operation timed out](https://kilobat.app/zh-hant/guides/ssh-port-22-operation-timed-out.html): ssh 向連接埠 22 送出連線請求，卻沒有收到回應。
- [Mac 上的 SSH 和 Git 逾時](https://kilobat.app/zh-hant/guides/ssh-git-timeouts.html): SSH 和 Git 需要與伺服器之間有正常的 TCP 連線。
- [Mac 上的 DNS 無法解析](https://kilobat.app/zh-hant/guides/dns-server-not-found.html): DNS 失敗時，Mac 無法將 apple.com 這類名稱轉換成 IP 位址。
- [公司代理伺服器憑證導致 Mac 上的終端機工具失效](https://kilobat.app/zh-hant/guides/corporate-proxy-certificates.html): 有些公司網路會檢查 HTTPS 流量。
