300 字
2 分钟
设置Git全局代理
设置和取消 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:7890git config --global https.proxy socks5://127.0.0.1:7890SOCKS5 代理(如 Clash)
git config --global http.proxy socks5://127.0.0.1:7890git 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.proxygit config --global --unset https.proxy查看当前代理配置
git config --global --get http.proxygit config --global --get https.proxy
# 或查看所有配置git config --global --list注意事项
-
端口号:
7890是常用代理端口,实际使用时请替换为你的代理软件端口 -
仅针对特定网站:如果只需要为 GitHub 设置代理:
Terminal window # 设置git config --global http.https://github.com.proxy socks5://127.0.0.1:7890# 取消git config --global --unset http.https://github.com.proxy -
临时代理:也可以使用环境变量临时设置:
Terminal window # 设置临时代理export http_proxy=http://127.0.0.1:7890export https_proxy=http://127.0.0.1:7890# 取消临时代理unset http_proxyunset https_proxy
验证代理是否生效
# 测试连接curl -I https://github.com# 或git clone https://github.com/username/repo.git提示:代理设置只影响 Git 操作,不会影响其他网络连接。