✓
完整解答与实操指引
程序员在终端执行 git clone、npm install、pip install 或 docker pull 时,命令行默认不会走系统代理。
方案一:为 Git 单独配置 Clash 代理(最常用)
Clash 本地默认监听 HTTP 端口为7890,在终端运行以下命令即可:
bash
点击选中复制
# 开启 Git 走本地 Clash 代理
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
# 需要关闭 Git 代理时执行:
git config --global --unset http.proxy
git config --global --unset https.proxy
方案二:PowerShell / Bash 临时全局代理
在当前终端窗口中临时注入环境变量(关闭终端后自动失效):
powershell
点击选中复制
# Windows PowerShell 执行:
$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"
bash
点击选中复制
# macOS / Linux Terminal 执行:
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
