type
status
date
slug
summary
tags
category
icon
password

一、针对 Git 的代理配置方式

方法一:配置 HTTP(S) 代理(适用于 VPN 提供 HTTP/HTTPS 代理端口)
# 设置代理 git config --global http.proxy http://127.0.0.1:PORT git config --global https.proxy http://127.0.0.1:PORT
🚫 取消代理(恢复直连):
git config --global --unset http.proxy git config --global --unset https.proxy
 
方法二:配置 SOCKS5 代理(适用于 Clash、V2rayN 提供的 SOCKS5 代理)
# 设置 socks5 代理 git config --global http.proxy 'socks5://127.0.0.1:1080' git config --global https.proxy 'socks5://127.0.0.1:1080'
⚠️ 注意:某些版本的 Git 不支持 socks5,此时推荐使用 polipo + clash 转发为 HTTP 代理。
 

二、代理配置是否生效验证方式

可以通过下面命令验证 Git 是否通过代理访问:
git config --global --get http.proxy git config --global --get https.proxy
或者用 curl 测试 GitHub:
curl -x socks5h://127.0.0.1:1080 https://github.com
 

三、针对 Cursor 的代理说明

Cursor 基于 VS Code,它的 Git 操作使用的是系统的 Git 环境,所以只要你配置了 git 的代理,Cursor 也会跟着走代理。
确保:
1. 系统已装 Git
2. git config --global 的代理设置正确
3. Cursor 的 Git 插件使用的是本地 Git(不是 Remote)
 

四、额外技巧(临时设置)

如果你不想全局设置代理,只对某一次 push 使用代理,可以用环境变量:
# 临时使用 socks5 代理推送 GIT_PROXY_COMMAND=socks5://127.0.0.1:1080 git push origin main
不过推荐直接设置 git config,更稳定。
 

五、代理无法访问 GitHub 的排查方法

如果设置代理后还是无法 push,可以:
  1. 用 curl 验证是否能访问 GitHub:
curl -x socks5h://127.0.0.1:1080 https://github.com
  1. 检查 DNS 问题(建议用 socks5h 而非 socks5,h 表示通过代理解析 DNS)