一、HTTP/HTTPS 仓库代理(克隆 https://xxx.git 用)

1. 设置全局 HTTP/HTTPS 代理(socks5 / http 两种)

SOCKS5 代理(Clash/V2Ray 常用,本地 7890 端口)

git config --global http.proxy socks5://127.0.0.1:7890
git config --global https.proxy socks5://127.0.0.1:7890

HTTP 代理(如本地 10809)

git config --global http.proxy http://127.0.0.1:10809
git config --global https.proxy http://127.0.0.1:10809

2. 只给当前仓库单独设置代理(不影响全局) 进入项目根目录执行,去掉 --global

git config http.proxy socks5://127.0.0.1:7890
git config https.proxy socks5://127.0.0.1:7890

3. 查看当前 Git 代理配置


#查看全局
git config --global --get http.proxy
git config --global --get https.proxy
# 查看所有配置(含代理)
git config --global --list

4. 清除全局 HTTP/HTTPS 代理

git config --global --unset http.proxy
git config --global --unset https.proxy

5. 清除当前仓库本地代理


git config --unset http.proxy
git config --unset https.proxy

二、SSH 仓库代理(你现在用 git@gitea.tianlingzi.top:xxx.git 场景)

Git 本身没有 ssh.proxy 参数,**SSH 走代理要改 ~/.ssh/config

1. 给 Gitea 域名单独配置 socks5 代理

编辑~/.ssh/config,添加:

Host gitea.tianlingzi.top
  HostName gitea.tianlingzi.top
  Port 6051
  User git
  StrictHostKeyChecking no
  # socks5 代理
  ProxyJump none
  ProxyCommand nc -x 127.0.0.1:7890 %h %p

保存后,所有 git@xxx 操作自动走代理。

2. 取消 SSH 代理 删掉上面

ProxyCommand 那一行即可。

3. 临时单次 SSH 走代理(克隆命令)

GIT_SSH_COMMAND="ssh -o ProxyCommand='nc -x 127.0.0.1:7890 %h %p' -p 6051" git clone git@gitea.tianlingzi.top:xxx/xxx.git

三、一键清除所有 Git 代理(复制直接运行)

git config --global --unset http.proxy
git config --global --unset https.proxy
git config --unset http.proxy
git config --unset https.proxy
最后修改:2026 年 06 月 18 日
如果觉得我的文章对你有用,请随意赞赏