Why a proxy matters
Slow or unstable networks—think corporate firewalls, cross-border latency, or flaky hotel Wi-Fi—can make cloning or fetching repositories painful. Pointing Git to an HTTP, HTTPS, or SOCKS proxy lets you reuse existing access infrastructure (jump hosts, Clash, Shadowsocks, V2Ray, enterprise proxies) and speed up operations.
Enable HTTP/HTTPS proxy quickly
Write the proxy endpoint directly into Git configuration:
# Global (~/.gitconfig)
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890
Limit the scope to a single repository by omitting --global and running inside the repo:
# Repository-only
git config http.proxy http://127.0.0.1:7890
git config https.proxy http://127.0.0.1:7890
Verify with git config --global -l | grep proxy.
Configure a SOCKS proxy
Many personal proxy tools expose a SOCKS port. Use the socks5:// scheme:
port=7891
git config --global http.proxy socks5://127.0.0.1:$port
git config --global https.proxy socks5://127.0.0.1:$port
Pick whichever protocol your proxy exposes; some tools offer both HTTP and SOCKS ports.
One-off proxy usage
Set environment variables for a single command when you do not want to touch config files:
HTTPS_PROXY=http://127.0.0.1:7890 \
HTTP_PROXY=http://127.0.0.1:7890 \
GIT_SSH_COMMAND="ssh -o ProxyCommand='nc -x 127.0.0.1:7890 %h %p'" \
git clone https://github.com/org/repo.git
The variables vanish after the command completes—handy for scripts and CI jobs.
Proxies for SSH remotes
SSH URLs ([email protected]:org/repo.git) rely on your SSH client. Configure ~/.ssh/config:
Host github.com
HostName github.com
User git
ProxyCommand nc -x 127.0.0.1:7890 %h %p
For SOCKS proxies, switch to an nc/ncat option that supports --proxy-type socks5.
Check that the proxy works
- Add verbosity:
GIT_TRACE=1 GIT_CURL_VERBOSE=1 git ls-remote https://github.com/org/repo.gitand look for the proxy address in the log. - Inspect your proxy dashboard (e.g., Clash GUI) to confirm Git traffic flows through it.
- Time
git fetchbefore and after—the difference is often obvious.
Troubleshooting checklist
- Is the proxy service running on the expected host and port?
- Do system-wide proxies or PAC files conflict with the manual Git settings?
- Corporate proxies may require credentials:
http://user:pass@proxy:port. - Exclude internal domains with
git config --global http.<domain>.proxy "".
Manage and remove proxy settings
git config --global --unset http.proxy
git config --global --unset https.proxy
When multiple entries exist, edit ~/.gitconfig or run git config --global --unset-all http.proxy to clean them up.
Best practices
- Prefer SOCKS when using Clash or V2Ray locally—it avoids some HTTP authentication quirks.
- In corporate environments standardise the proxy value in
~/.gitconfigand distribute it to teammates. - For scripts or CI jobs, rely on environment variables so the proxy lifecycle is tied to the process.
- Combine Git proxy settings with SSH config to cover both HTTPS and SSH remotes.
With these recipes Git can adapt to restrictive networks, allowing you to swap proxy strategies whenever the environment changes.