VS Code + WSL 下 GitHub 访问不稳定 & Copilot/Codex 一直 Thinking 的完整解决方案
本文记录一次开发环境排查过程:从 VS Code + WSL 环境下 GitHub 克隆失败,到 Copilot/Codex 长时间停在 "Thinking…" 的完整解决步骤。
📌 一、问题概述
使用 VS Code + WSL 进行开发时可能遇到以下问题:
❌ 1. Git clone 失败
fatal: unable to access 'https://github.com/...': Failed to connect to 172.xx.xx.xx port xxxx
❌ 2. VS Code Copilot / Codex 一直 "Thinking…"
- 无法生成补全
- 长时间转圈
- VS Code 日志提示连接境外服务失败
🔍 二、核心原因(理解网络结构非常重要)
WSL 的网络结构分为 3 层:
| 层级 | 属于哪里 | 特点 |
|---|---|---|
| Windows 主机 | VS Code 本体运行、网络辅助软件运行 | 使用主机网络 |
| WSL Linux | Git、curl、Copilot 后台运行 | 127.0.0.1 指的是 WSL 自身 |
| Remote WSL 扩展 | VS Code 与 WSL 的桥梁 | 同时依赖两端的网络配置 |
❗关键点:
WSL 中的 127.0.0.1 不是 Windows,而是 Linux 自身。
当需要访问境外服务(如 GitHub、Copilot)时,WSL 必须正确访问到主机的网络出口。
主机出口地址可通过 WSL 查询:
cat /etc/resolv.conf | grep nameserver
示例:
nameserver 172.25.176.1
这个地址每次重启电脑可能变化,因此很多网络相关设置会失效。
⚙️ 三、Git clone 不稳定的解决方案
1️⃣ 清理错误的网络配置
git config --unset http.proxy
git config --unset https.proxy
git config --global --unset http.proxy
git config --global --unset https.proxy
unset HTTP_PROXY HTTPS_PROXY http_proxy https_proxy ALL_PROXY all_proxy
2️⃣ 测试 WSL 是否能直连 GitHub
curl -I https://github.com

