Learn how to configure and remove Git proxy settings to work behind firewalls or restricted networks. This guide covers HTTP, HTTPS, and SOCKS proxies, including global and per-repository settings.
Git allows users to configure proxy settings for accessing repositories through a proxy server. This is particularly useful when working in restricted network environments. This guide covers how to configure and remove proxy settings for both HTTPS and SSH connections in Git.
Git uses the http.proxy setting to configure an HTTP or HTTPS proxy.
Open a terminal or command prompt.
Set the proxy for Git using the following command:
1git config --global http.proxy http://proxyuser:[email protected]:port
2
3Replace proxyuser with your proxy username.
Replace proxypassword with your proxy password (if required).
Replace proxy.server.com with the proxy server address.
Replace port with the port number.
1git config --global https.proxy https://proxyuser:[email protected]:port
2
3Run the following command to check if the proxy is set:
1git config --global --get http.proxy
2
3If set correctly, it will display the proxy address.
Git uses SSH for secure connections. To use a proxy for SSH, modify the SSH configuration file.
1nano ~/.ssh/config
2
31Host github.com
2 ProxyCommand nc -X connect -x proxy.server.com:port %h %p
3
4Replace proxy.server.com and port with your proxy details.
For Windows, use:
1Host github.com
2 ProxyCommand connect -H proxy.server.com:port %h %p
3
4Save and exit the file.
Test the SSH connection:
1ssh -T git@github.com
2
3To remove the proxy setting for HTTP and HTTPS:
1git config --global --unset https.proxy
2
3To verify removal:
1git config --global --get http.proxy
2git config --global --get https.proxy
3
4If nothing is returned, the proxy has been removed successfully.
1nano ~/.ssh/config
2
3Locate and remove or comment out the ProxyCommand lines.
Save the file and test:
1ssh -T git@github.com
2
3Ensure the proxy server details are correct.
If using authentication, check for special characters in the password (encode them if necessary).
Test connectivity with:
1curl -x http://proxy.server.com:port https://github.com
2
31git config --system --unset http.proxy
2
31nano ~/.gitconfig
2
3and remove proxy entries.
Setting and removing a proxy in Git is essential for working behind firewalls or corporate networks. By following this guide, you can configure and troubleshoot proxy settings for both HTTPS and SSH connections efficiently.
If you have any issues, verify your network settings and proxy credentials.
For more information, you can also read the chinese page as follow: https://gist.github.com/laispace/666dd7b27e9116faece6