Git (HTTPS and SSH)
HTTPS clones use http.proxy; SSH clones use ProxyCommand, switching to port 443 when needed.
HTTPS
# global
git config --global http.proxy http://127.0.0.1:7898
# GitHub only (recommended)
git config --global http.https://github.com.proxy http://127.0.0.1:7898
# unset
git config --global --unset http.proxy
git config --global --unset http.https://github.com.proxyGit also uses the https_proxy environment variable when it is set.
SSH (git@github.com)
SSH ignores HTTP proxy variables, so configure a ProxyCommand in ~/.ssh/config.
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 ships connect):
Host github.com
HostName ssh.github.com
Port 443
User git
ProxyCommand connect -S 127.0.0.1:7898 %h %pNote
ssh.github.com:443 is GitHub's official SSH-over-HTTPS port, useful on networks that restrict port 22.
On Linux, nc must be the OpenBSD version (netcat-openbsd on Debian/Ubuntu) to support -X.
Verify:
ssh -T git@github.comTips for large repositories
git clone --depth 1 https://github.com/owner/repo # shallow clone
git clone --filter=blob:none https://github.com/owner/repo # fetch file contents on demand