How to Set and Remove Git Configuration Proxy 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
3
-
Replace 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.
- If using an HTTPS proxy, use:
1git config --global https.proxy https://proxyuser:[email protected]:port
2
3
Run the following command to check if the proxy is set:
1git config --global --get http.proxy
2
3
If 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.
- Open the SSH config file (create it if it doesn’t exist):
1nano ~/.ssh/config
2
3
- Add the following lines:
1Host github.com
2 ProxyCommand nc -X connect -x proxy.server.com:port %h %p
3
4
-
Replace 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
4
-
Save and exit the file.
-
Test the SSH connection:
1ssh -T git@github.com
2
3
To remove the proxy setting for HTTP and HTTPS:
1git config --global --unset https.proxy
2
3
To verify removal:
1git config --global --get http.proxy
2git config --global --get https.proxy
3
4
If nothing is returned, the proxy has been removed successfully.
- Open the SSH config file:
1nano ~/.ssh/config
2
3
-
Locate and remove or comment out the ProxyCommand lines.
-
Save the file and test:
1ssh -T git@github.com
2
3
-
Ensure 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
3
- Use --system instead of --global if the setting is applied system-wide:
1git config --system --unset http.proxy
2
3
- Manually check the Git config file:
1nano ~/.gitconfig
2
3
and 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