錯誤訊息
Mac 上的 Git:「Could not resolve host: github.com」
Git 無法取得 github.com 的位址。HTTPS 遠端由 Git 印出 curl 的訊息,SSH 遠端則由 ssh 印出自己的訊息。
症狀
- 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 錯誤。遠端打錯字,名稱就不存在。
如何檢查
顯示儲存庫的遠端 URL。
git remote -v透過 macOS 解析器查詢 github.com。
dscacheutil -q host -a name github.com顯示 Git 的代理伺服器設定和你的代理伺服器環境變數。
git config --get http.proxy env | grep -i proxy用 curl 測試 HTTPS 路徑。
curl -I https://github.com
如何修正
如果所有名稱都查詢失敗,就修正 DNS。請參閱「Mac 上 DNS 無法解析」。
如果網路需要代理伺服器,就為 Git 設定。
git config --global http.proxy http://proxy.example.com:8080如果舊的代理伺服器設定有誤,就移除它。
git config --global --unset http.proxy如果遠端 URL 打錯字,就更正它。
git remote set-url origin https://github.com/OWNER/REPO.git
使用 Kilobat
Kilobat 的連線診斷會逐層測試主機:網路、代理伺服器、DNS、規則、IPv4、IPv6、TLS 和伺服器,並指出失敗的是哪一層。
kilobat why github.com這些 Kilobat 檢查都是免費的。AI 代理程式可透過 MCP 以
diagnose_connection和diagnose_network執行。請參閱找出某個網站或 API 連不上的原因。
常見問題
GitHub 掛了嗎?
有可能,但查詢錯誤通常出在本機。如果 dscacheutil 查得到其他名稱,唯獨查不到 github.com,就檢查你的 DNS 或過濾器。
資料來源
- curl:libcurl error codes
- 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> 開啟。