Git(HTTPS 与 SSH)
HTTPS 克隆走 http.proxy;SSH 克隆走 ProxyCommand,必要时改用 443 端口。
HTTPS
# 全局
git config --global http.proxy http://127.0.0.1:7898
# 只对 GitHub 生效(推荐)
git config --global http.https://github.com.proxy http://127.0.0.1:7898
# 取消
git config --global --unset http.proxy
git config --global --unset http.https://github.com.proxy设置了 https_proxy 环境变量时,Git 也会使用它。
SSH(git@github.com)
SSH 协议不读取 HTTP 代理变量,需要在 ~/.ssh/config 中配置 ProxyCommand。
macOS / Linux:
Host github.com
HostName ssh.github.com
Port 443
User git
ProxyCommand nc -X 5 -x 127.0.0.1:7898 %h %pWindows(Git for Windows 自带 connect):
Host github.com
HostName ssh.github.com
Port 443
User git
ProxyCommand connect -S 127.0.0.1:7898 %h %p注意
ssh.github.com:443 是 GitHub 官方提供的 SSH over HTTPS 端口,适合 22 端口受限的网络。
Linux 上的 nc 需要是 OpenBSD 版本(Debian/Ubuntu 包名 netcat-openbsd)才支持 -X 参数。
验证:
ssh -T git@github.com大仓库小技巧
git clone --depth 1 https://github.com/owner/repo # 浅克隆
git clone --filter=blob:none https://github.com/owner/repo # 按需拉取文件内容