Git、SSH 与 GitHub 加速代理配置(HTTPS 与 SSH 端口分离教程)
核心结论速览
不要全局给 Git 设死代理(会影响国内公司内网 GitLab);最优雅的做法是仅针对 `github.com` 域名配置 HTTPS 代理,并在 `~/.ssh/config` 中用 `ProxyCommand` 让 SSH 走本地 SOCKS5/HTTP 端口。
1. 仅对 GitHub 配置 HTTPS 代理
假设本地代理端口为 7897,在终端仅针对 GitHub 生效(不影响 Gitee 或内网仓库):
git config --global http.https://github.com.proxy http://127.0.0.1:7897
2. SSH 走本地代理或 443 端口
在 ~/.ssh/config 添加以下配置(Windows Git Bash 可使用自带 connect.exe):
Host github.com
User git
Hostname ssh.github.com
Port 443
ProxyCommand connect -S 127.0.0.1:7897 %h %p