6

I am inside a corporate network that requires a proxy to be set up to access servers outside the intranet.

So, to be able to git clone from, say, github we have set up the HTTP_PROXY environment variable. That works fine.

However, we also have an internal git server. To properly access that we must not use the proxy. It works if I set this up in the .gitconfig file:

[http "http://stash.fabricam.com/"]
    proxy = 

Since the proxy is set to the empty value here, no proxy is used for git clone from the server in question.

However, I would like to be able to create this configuration in a script, using git config --global. But I can't figure out how to do it.

These do not work

git config --global http.http://stash.fabricam.com/ ""
git config --global http.http%3A%2F%2Fstash.fabricam.com%2F ""
git config --global http.http%3A%2F%2Fstash.fabricam.com%2F ''
git config --global --add http.http%3A%2F%2Fstash.fabricam.com%2F

As you can see I have tried to use the percent encoding, but that does not help.

I have read this post, but I don't want to set this on every command, I really want to modify the .gitconfig file.

I have attempted setting up the no_proxy environment variable, but git does not seem to notice it.

I am in a Windows environment, running git 2.7.1

edit

Thanks to @choroba I got a bit further.

The behavior of this command is different depending on the shell:

git config --global http."http://stash.fabricam.com/".proxy ''
  • In PowerShell, this does nothing at all.

  • In cmd.exe

it creates this setting

[http "http://stash.fabricam.com/"]
    proxy = ''

But that does not work. The empty string is not the same as no string at all. It will result in this behavior:

> git clone http://stash.fabricam.com/test.git
Cloning into 'test'...
fatal: unable to access 'http://stash.fabricam.com/test.git/':
 Couldn't resolve proxy ''''
  • In bash (that comes with git on windows) the command does work, and sets up the correct empty value. But I'd rather not script in bash when on windows, so this is not a good solution for me.
Cœur
  • 37,241
  • 25
  • 195
  • 267
Klas Mellbourn
  • 42,571
  • 24
  • 140
  • 158

1 Answers1

6

You have to include the .proxy key:

git config --global http."http://stash.fabricam.com/".proxy ''

In PowerShell, the empty string can be specified using backquotes:

`"`"
choroba
  • 231,213
  • 25
  • 204
  • 289
  • Good suggestion. Weirdly, I get no error when I execute that command, but it does not seem to do anything. When I use a non-empty string, it works to set it to that string. But empty string does not work. I think that might be the syntax for un-setting a config setting. – Klas Mellbourn Feb 16 '16 at 13:46
  • @KlasMellbourn: Works for me, git 2.7.0 in cygwin. – choroba Feb 16 '16 at 13:49
  • Ok, I use Powershell by default. Discovery: It does nothing in powershell. In cmd.exe it sets proxy to ''. In bash (that comes with git) it is correctly set to nothing. – Klas Mellbourn Feb 16 '16 at 14:19
  • @KlasMellbourn: OK, how do you specify an empty argument in PowerShell? – choroba Feb 16 '16 at 14:45
  • Don't know really. It is sort of a hybrid world, using the unix-like git command in PowerShell. – Klas Mellbourn Feb 16 '16 at 15:03
  • 1
    @KlasMellbourn: Have you tried `""` instead of `''`? – choroba Feb 16 '16 at 15:47
  • Yes. Both behave the same in PowerShell, namely, do nothing. – Klas Mellbourn Feb 16 '16 at 19:48
  • Yes! That did it. This works in PowerShell: `git config --global http."http://stash.fabricam.com/".proxy \`"\`"`. Maybe you should add it to your answer, for clarity. – Klas Mellbourn Feb 16 '16 at 19:59