我在公司网络中,需要设置代理才能访问 Intranet 外部的服务器。
因此,为了能够从比方说 github 上git clone
,我们已经设置了HTTP_PROXY
环境变量。这很好用。
但是,我们也有一个内部 git 服务器。要正确访问我们必须不使用代理。如果我在 .gitconfig
文件中设置它,它会起作用:
[http "http://stash.fabricam.com/"]
proxy =
由于此处代理设置为空值,因此没有代理用于来自相关服务器的 git clone
。
但是,我希望能够使用 git config --global
在脚本中创建此配置。但我不知道该怎么做。
这些都行不通
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
如您所见,我已尝试使用 percent encoding ,但这没有帮助。
我已阅读 this post , 但我不想在每个命令上都设置它,我真的想修改 .gitconfig
文件。
我尝试设置 no_proxy
环境变量,但 git
似乎没有注意到它。
我在Windows环境下,运行git 2.7.1
编辑
感谢@choroba,我更进一步了。
此命令的行为因 shell 而异:
git config --global http."http://stash.fabricam.com/".proxy ''
在
PowerShell
中,这根本不执行任何操作。在
cmd.exe
它创建了这个设置
[http "http://stash.fabricam.com/"]
proxy = ''
但是那行不通。空字符串与根本没有字符串是不一样的。它将导致这种行为:
> 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 ''''
- 在
bash
(Windows 上的 git 附带)中,命令确实起作用,并设置正确的空值。但我不想在 Windows 上使用 bash 编写脚本,所以这对我来说不是一个好的解决方案。
最佳答案
您必须包含 .proxy
键:
git config --global http."http://stash.fabricam.com/".proxy ''
在 PowerShell 中,可以使用反引号指定空字符串:
`"`"
关于git - 如何从命令行将 git config 变量设置为空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35433326/