How to temporarily disable git http proxy
Asked Answered
T

3

34

I am using git behind a corporate firewall, and I am successfully cloning external projects by using the http.proxy --global config.

My problem arises when I want to clone through http on the intranet. I suspect that the proxy config interferes with the intranet request.

I know I could reset the config before using the intranet, but that is not very user friendly.

I also saw this answer, but it seems to apply only to an existing repository.

Is there a way to deactivate the proxy usage only for one command invocation? In this case, the initial clone?

Tho answered 22/10, 2013 at 16:55 Comment(0)
C
43

I always set:

no_proxy=.mycompany

(export if I am on Unix, or a simple set on Windows)

It is enough to bypass the proxy for all intranet url ending with ".mycompany".

See for an example:

I use it in my own project: .proxy.example:

export http_proxy=http://username:[email protected]:port
export https_proxy=http://username:[email protected]:port
export no_proxy=.company localhost
Confuse answered 22/10, 2013 at 17:50 Comment(1)
I wish I could up vote it multiple times! I spent days trying to figure this damn thing out! Thank you man!Sloatman
A
27

What I like to do is set two Git aliases:

~/.gitconfig

[alias]
        noproxy = config --global --remove-section http
        proxy = config --global http.proxy http://127.0.0.1:9666

Note that I didn't use config --global --unset http.proxy to reset the proxy because that leaves behind the [http] section heading, so after repeatedly enabling and disabling the proxy your .gitconfig will be polluted with a bunch of empty [http] section headings. No big deal, but it's just annoying.


In some cases, such as behind corporate firewalls, you need to configure ~/.ssh/config instead. The setup becomes slightly more complicated:

~/.gitconfig

[alias]
        noproxy = !sh -c 'cp ~/.ssh/config.noproxy ~/.ssh/config'
        proxy = !sh -c 'cp ~/.ssh/config.proxy ~/.ssh/config'

~/.ssh/config.noproxy

Host github.com-username
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

~/.ssh/config.proxy

Host *
  ProxyCommand connect -H 127.0.0.1:9666 %h %p

Host github.com-username
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa

You can even combine the two methods by changing the aliases to this:

[alias]
        noproxy = !sh -c 'git config --global --remove-section http 2> /dev/null && cp ~/.ssh/config.noproxy ~/.ssh/config'
        proxy = !sh -c 'git config --global http.proxy http://127.0.0.1:9666 && cp ~/.ssh/config.proxy ~/.ssh/config'

Now I can simply type git noproxy to disable the proxy and git proxy to enable it. You can even switch among multiple proxies by creating more aliases.

Ahriman answered 9/11, 2016 at 14:30 Comment(0)
G
3

In my case, I was able to disable git clone requests going through the proxy in my corporate setting by executing

git config --global --add remote.origin.proxy ""

As per the git documentation, this disables all requests to that remote repo named origin.

Gracye answered 28/8, 2018 at 17:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.