Git (HTTPS and SSH)

HTTPS clones use http.proxy; SSH clones use ProxyCommand, switching to port 443 when needed.

HTTPS

bash
# 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.proxy

Git 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:

sshconfig
Host github.com
  HostName ssh.github.com
  Port 443
  User git
  ProxyCommand nc -X 5 -x 127.0.0.1:7898 %h %p

Windows (Git for Windows ships connect):

sshconfig
Host github.com
  HostName ssh.github.com
  Port 443
  User git
  ProxyCommand connect -S 127.0.0.1:7898 %h %p
Note

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:

bash
ssh -T git@github.com

Tips for large repositories

bash
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