I have some repos that I work with that are at the public github.com and require a proxy server from work.
I have other repos in our Enterprise Github instance that is behind the firewall and will fail when directed to our proxy.
What is the best way to manage this need for multiple proxies? I can use git config --global along with setting the http.proxy and https.proxy keys to the proxy to get github.com repos connecting, but then Enterprise Github is broken and I have to clear those keys to get it working again.
How can I manage these two sources that require different proxy settings without manually changing the proxy? Am I stuck using a script every time I switch projects?
From the link VonC gave to this question, I was able to put together the correct commands to get this done, but those answers are very convoluted (and sometimes difficult to understand the correct syntax), so I thought I would consolidate my answer here for posterity:
One solution is to setup only github.com for the proxy with:
> git config --global http.https://github.com.proxy http://[user:pass@]<proxy URL>:<port>
> git config --global https.https://github.com.proxy http://[user:pass@]<proxy URL>:<port>
This looks a little funky because you are embedding https://github.com right in the middle of the normal http.proxy statement. This is how you create a proxy that is attached to a specific site.
Alternately, you can configure the proxy for all sites, then remove the proxy just for your internal Github site:
> git config --global http.proxy http://[user:pass@]<proxy URL>:<port>
> git config --global https.proxy http://[user:pass@]<proxy URL>:<port>
This applies the proxy to everything, and then do the following to tell Git to not use a proxy for your internal Git site:
> git config --global http.<Git Site URL>.proxy ""
> git config --global https.<Git Site URL>.proxy ""
where <Git Site URL> is the fully qualified domain name, such as http://github.mycompany.com - what you would type into the browser to get there.
http://proxy:port, and not https://proxy:port (i.e. just http, NOT https), for both http.proxy and https.proxy.As I explained in "Only use a proxy for certain git urls/domains?"
, you can set a proxy just for github.com.
But in your case, I would stick with the classic HTTP(S)_PROXY environment variable (no need for git config commands)
Simply add a NO_PROXY environment variable with the domain of your private Git hosting server, and Git won't use the proxy when cloning/pushing/pulling from said private server.
set NO_PROXY=.myserver.org
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With