git - 如何从命令行将 git config 变量设置为空值

标签 git proxy

我在公司网络中,需要设置代理才能访问 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/

相关文章:

git - 在 GUI 中探索 git-diff 输出?

python - 如何让 PhantomJS 通过代理列表进行连接?

django - 使用proxy_pass的nginx位置路径

通过 Apache-Redirect 代理进行 Node.js Passport 身份验证

nginx - nginx 登录背后的 keycloak 失败,post 中缺少端口号等

git - git 项目中手动重命名文件的修复方法是什么?

git - 如何忽略除一个之外的所有 dist 文件夹?

php - 我如何将apache服务器配置为代理http ://localhost:3000/and exclude some URL?

git - 如何在不更改提交消息的情况下修改提交(重用前一个)?

java - 如何配置 github 操作以使用 Maven 进行编译并依赖于其他私有(private)存储库?