我在需要设置代理以访问 Intranet 外部服务器的公司网络内。
因此,为了能够git clone从 github 中获取,我们已经设置了HTTP_PROXY环境变量。这很好用。
但是,我们也有一个内部 git 服务器。为了正确访问,我们不能使用代理。如果我在.gitconfig文件中设置它,它会起作用:
[http "http://stash.fabricam.com/"]
proxy =
Run Code Online (Sandbox Code Playgroud)
由于此处将代理设置为空值,因此不使用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
Run Code Online (Sandbox Code Playgroud)
如您所见,我尝试使用百分比编码,但这无济于事。
我已经阅读了这篇文章,但我不想在每个命令上都设置它,我真的想修改.gitconfig文件。
我曾尝试设置no_proxy环境变量,但git似乎没有注意到。
我在 Windows 环境中,运行 git 2.7.1
编辑
感谢@choroba,我走得更远。
此命令的行为因外壳而异:
git config --global http."http://stash.fabricam.com/".proxy ''
Run Code Online (Sandbox Code Playgroud)
在 中PowerShell,这什么都不做。
在 cmd.exe
它创建了这个设置
[http "http://stash.fabricam.com/"]
proxy = ''
Run Code Online (Sandbox Code Playgroud)
但那是行不通的。空字符串与根本没有字符串不同。这将导致这种行为:
> 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 ''''
Run Code Online (Sandbox Code Playgroud)
bash(Windows 上的 git 附带)中,该命令确实有效,并设置了正确的空值。但是我宁愿不在 Windows 上用 bash 编写脚本,所以这对我来说不是一个好的解决方案。您必须包含.proxy密钥:
git config --global http."http://stash.fabricam.com/".proxy ''
Run Code Online (Sandbox Code Playgroud)
在 PowerShell 中,可以使用反引号指定空字符串:
`"`"
Run Code Online (Sandbox Code Playgroud)