git clone 支持在命令行临时设置proxy
git clone 支持在命令行临时设置代理,不需要改全局配置,主要有两种常用方式:

1. 在 git clone 命令里直接用 -c 指定代理
这样只对本次 clone 生效,不会影响其他 git 操作。
git-chttp.proxy=http://127.0.0.1:7890 \-chttps.proxy=http://127.0.0.1:7890 \ clone https://github.com/xxx/yyy.git 如果是 SOCKS5 代理:
git-chttp.proxy=socks5://127.0.0.1:7890 \-chttps.proxy=socks5://127.0.0.1:7890 \ clone https://github.com/xxx/yyy.git 2. 使用环境变量临时代理
只对当前终端会话有效,适合一次性操作:
# HTTP 代理exporthttp_proxy=http://127.0.0.1:7890 exporthttps_proxy=http://127.0.0.1:7890 # SOCKS5 代理exporthttp_proxy=socks5://127.0.0.1:7890 exporthttps_proxy=socks5://127.0.0.1:7890 git clone https://github.com/xxx/yyy.git 完成后取消代理:
unset http_proxy unset https_proxy ✅ 建议
- 如果你只是偶尔需要代理,用 方法 1(
git -c临时)更安全,不会影响后续操作。 - 如果频繁用代理,可以在
~/.gitconfig里配置http.https://github.com.proxy。