设置和取消 Git 全局代理的命令如下:
设置 Git 全局代理
HTTP/HTTPS 代理
# 设置 HTTP 代理
git config --global http.proxy http://127.0.0.1:7890
# 设置 HTTPS 代理
git config --global https.proxy http://127.0.0.1:7890
# 一次性设置(常用)
git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890
SOCKS5 代理(如 Clash)
git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890
取消 Git 全局代理
# 取消 HTTP 代理
git config --global --unset http.proxy
# 取消 HTTPS 代理
git config --global --unset https.proxy
# 一次性取消全部(推荐)
git config --global --unset http.proxy
git config --global --unset https.proxy
查看当前代理配置
git config --global --get http.proxy
git config --global --get https.proxy
# 或查看所有配置
git config --global --list
注意事项
- 端口号:
7890是常用代理端口,实际使用时请替换为你的代理软件端口 仅针对特定网站:如果只需要为 GitHub 设置代理:
# 设置 git config --global http.https://github.com.proxy socks5://127.0.0.1:7890 # 取消 git config --global --unset http.https://github.com.proxy临时代理:也可以使用环境变量临时设置:
# 设置临时代理 export http_proxy=http://127.0.0.1:7890 export https_proxy=http://127.0.0.1:7890 # 取消临时代理 unset http_proxy unset https_proxy
验证代理是否生效
# 测试连接
curl -I https://github.com
# 或
git clone https://github.com/username/repo.git
提示:代理设置只影响 Git 操作,不会影响其他网络连接。
暂无评论