11.10.2025

Configure Git to Work Behind a Proxy: HTTP, HTTPS, and SOCKS5 Setup

head-image

Corporate networks and restricted environments often require routing traffic through proxy servers to reach external resources. Git operations like clone, fetch, and push fail when direct internet access is blocked, forcing developers to configure proxy settings manually. Understanding how to set HTTP, HTTPS, and SOCKS5 proxies at global, per-repository, and per-command levels ensures uninterrupted version control access across firewall boundaries and VPN connections.

What is Git Proxy Configuration?

Git proxy configuration tells Git to route network requests through an intermediary proxy server instead of connecting directly to remote repositories. Git supports HTTP, HTTPS, and SOCKS5 proxies via libcurl. Proxy settings apply to HTTPS-based repository URLs (e.g., https://github.com/user/repo.git) and can include authentication credentials for proxies requiring username/password validation. SSH-based repositories ([email protected]:user/repo.git) require separate SSH proxy configuration through ProxyCommand directives.

Setting HTTP/HTTPS Proxy

Configure Git to use an HTTP or HTTPS proxy globally for all repositories:

# Set HTTP proxy
git config --global http.proxy http://proxy.example.com:8080

# Set HTTPS proxy
git config --global https.proxy http://proxy.example.com:8080

Include authentication credentials when the proxy requires login:

git config --global http.proxy http://username:[email protected]:8080

For URL-encoded special characters in passwords, use percent encoding (e.g., @ becomes %40).

Setting SOCKS5 Proxy

Use SOCKS5 proxies for Git traffic by specifying the socks5:// or socks5h:// protocol. The socks5h:// variant performs DNS resolution through the proxy:

# SOCKS5 without DNS resolution
git config --global http.proxy socks5://127.0.0.1:1080

# SOCKS5 with DNS resolution via proxy
git config --global http.proxy socks5h://127.0.0.1:1080

The socks5h:// option is recommended when the proxy handles DNS lookups, preventing DNS leaks on restrictive networks.

Domain-Specific Proxy Configuration

Apply proxy settings to specific domains or repositories without affecting global configuration:

# Proxy only for GitHub
git config --global http.https://github.com.proxy http://proxy.example.com:8080

# Proxy for specific corporate GitLab instance
git config --global http.https://gitlab.corp.com.proxy socks5h://127.0.0.1:1080

This approach allows mixing proxied and direct connections based on repository URLs.

Per-Repository Proxy Settings

Override global proxy settings for individual repositories:

cd /path/to/repo
git config http.proxy http://different-proxy.example.com:3128

Remove repository-specific proxy to revert to global settings:

git config --unset http.proxy

Per-Command Proxy Usage

Set proxy temporarily for a single Git command without modifying configuration files:

git clone https://github.com/user/repo.git \
  -c http.proxy=socks5://127.0.0.1:7890 \
  -c https.proxy=socks5://127.0.0.1:7890

This technique is useful for one-time operations or testing proxy connectivity.

Configuring SSH Proxy

For SSH-based repository URLs, configure proxy settings in ~/.ssh/config using ProxyCommand:

Host github.com
  User git
  ProxyCommand nc -X 5 -x 127.0.0.1:1080 %h %p

Alternatively, use socat for SOCKS5 proxying:

Host github.com
  User git
  ProxyCommand socat - PROXY:proxy.example.com:%h:%p,proxyport=8080

Removing Proxy Settings

Unset proxy configuration to restore direct connections:

# Remove global HTTP proxy
git config --global --unset http.proxy

# Remove global HTTPS proxy
git config --global --unset https.proxy

# Remove domain-specific proxy
git config --global --unset http.https://github.com.proxy

Verify removal by checking Git configuration:

git config --global --list | grep proxy

Operational Tips

  • Test Proxy Connectivity: Verify proxy accessibility with curl before configuring Git to isolate connectivity issues.
  • Avoid Credential Exposure: Store proxy credentials in environment variables (HTTP_PROXY, HTTPS_PROXY) and reference them in scripts instead of hardcoding passwords.
  • Use Environment Variables: Set http_proxy and https_proxy environment variables as fallback for tools that respect standard proxy variables.
  • Check Corporate PAC Files: Review corporate proxy auto-config (PAC) files to identify correct proxy servers and ports for internal networks.

Conclusion

Configuring Git to work behind proxies ensures seamless repository access in corporate and restricted environments. By mastering global, per-repository, and domain-specific proxy settings, developers maintain productivity without sacrificing network security policies.

For efficient incident management and to prevent on-call burnout, consider using Akmatori. Akmatori automates incident response, reduces downtime, and simplifies troubleshooting.

Additionally, for reliable virtual machines and bare metal servers worldwide, check out Gcore.

Automate incident response and prevent on-call burnout with AI-driven agents!