You need to define the GIT_SSH_COMMAND environment variable first
In it, you can redefine the ssh command, in order to use your socks proxy setting
ssh -D $port_number $hostname
# or
ssh -D $port_number $username@$hostname
Or using a proxycommand nc (or ncat on Windows)
The point is: once ssh is working with your socks5 proxy, you can define the same syntax in GIT_SSH_COMMAND, and Git will use the right ssh command.
You can also test it with a local configuration:
git -c core.sshCommand='ssh -D 9998 [email protected]' git pull
git -c core.sshCommand='ssh -D 9999 127.0.0.1' git pull
Git 2.46 (Q3 2024), rc0 batch 2 adds on the topic:
See commit 70405ac, commit 804ecbc, commit c98f78b, commit 2101341 (09 Jul 2024) by brian m. carlson (bk2204).
(Merged by Junio C Hamano -- gitster -- in commit d6c8636, 16 Jul 2024)
gitfaq: add documentation on proxies
Signed-off-by: brian m. carlson
Many corporate environments and local systems have proxies in use.
Note the situations in which proxies can be used and how to configure them.
At the same time, note what standards a proxy must follow to work with Git.
Explicitly call out certain classes that are known to routinely have problems reported various places online, including in the Git for Windows issue tracker and on Stack Overflow, and recommend against the use of such software, noting that they are associated with myriad security problems (including, for example, breaking sandboxing and image integrity (chromium issue 40285192), and, for TLS middleboxes, the use of insecure protocols and ciphers and lack of certificate verification (PDF)).
Don't mention the specific nature of these security problems in the FAQ entry because they are extremely numerous and varied and we wish to keep the FAQ entry relatively brief.
gitfaq now includes in its man page:
Can I use a proxy with Git?
Yes, Git supports the use of proxies. Git honors the standard http_proxy, https_proxy, and no_proxy environment variables commonly used on Unix, and it also can be configured with http.proxy and similar options for HTTPS (see git config).
The http.proxy and related options can be customized on a per-URL pattern basis.
In addition, Git can in theory function normally with transparent proxies that exist on the network.
For SSH, Git can support a proxy using OpenSSH's ProxyCommand. Commonly used tools include netcat and socat. However, they must be configured not to exit when seeing EOF on standard input, which usually means that netcat will require -q and socat will require a timeout with something like -t 10.
This is required because the way the Git SSH server knows that no more requests will be made is an EOF on standard input, but when that happens, the server may not have yet processed the final request, so dropping the connection at that point would interrupt that request.
An example configuration entry in ~/.ssh/config with an HTTP proxy might look like this:
Host git.example.org
User git
ProxyCommand socat -t 10 - PROXY:proxy.example.org:%h:%p,proxyport=8080
Note that in all cases, for Git to work properly, the proxy must be completely transparent.
The proxy cannot modify, tamper with, or buffer the connection in any way, or Git will almost certainly fail to work.
Note that many proxies, including many TLS middleboxes, Windows antivirus and firewall programs other than Windows Defender and Windows Firewall, and filtering proxies fail to meet this standard, and as a result end up breaking Git.
Because of the many reports of problems and their poor security history, we recommend against the use of these classes of software and devices.