How to set up a proxy for git?
Published:
This is a note on how to set up a proxy for git.
How to set up a proxy for git? 1
Transport protocols supported by Git
Git supports transport protocols including ssh, git, http and https. The following syntaxes may be used with them:
ssh://[<user>@]<host>[:<port>]/<path-to-git-repo>
git://<host>[:<port>]/<path-to-git-repo>
http[s]://<host>[:<port>]/<path-to-git-repo>
Git uses the proxy method of the HTTP / HTTPS transport protocol
- Repositories for all domains:
git config --global http.proxy <protocol>://<host>:<port>
- Repositories for specific domains:
git config --global http.<url>.proxy <protocol>://<host>:<port>
Git uses the proxy method of the SSH transport protocol
- Windows - HTTP
Edit ~/.ssh/config file:
Host github.com
User git
ProxyCommand connect -H 127.0.0.1:7890 %h %p
- Windows - SOCKS
Edit ~/.ssh/config file:
Host github.com
User git
ProxyCommand connect -S 127.0.0.1:7891 %h %p
Cancel proxy
- For HTTP / HTTPS:
git config --global --unset http.proxy
git config --global --unset https.proxy
- For SSH:
Edit ~/.ssh/config file
Add “#” before the ProxyCommand line.
References: https://ericclose.github.io/git-proxy-config.html. ↩