git - 只对某些 git url/域使用代理?

标签 git github proxy

是否可以将 git 配置为仅对特定域使用代理?

我想使用我们的公司代理访问 Github,但为了访问我们自己的内部 git 存储库而将其关闭。

我正在使用 Bower,它需要在我们的防火墙和 github 中都需要项目,所以我不能按照项目设置来执行此操作。它需要是某种全局配置选项。有什么想法吗?

最佳答案

要添加另一种可能性,您可以define a proxy through the git config http.proxy .

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:proxyport

但真正巧妙的是,starting git1.8.5 (October 2013) ,您可以为每个网址设置 http 设置

http.*”变量现在可以根据配置应用的 URL 指定
例如,

[http]
   sslVerify = true
[http "https://weak.example.com/"]
   sslVerify = false

would flip http.sslVerify off only when talking to that specified site.


参见 commit d4770964d5 :

$ git config --bool --get-urlmatch http.sslVerify https://good.example.com
true
$ git config --bool --get-urlmatch http.sslVerify https://weak.example.com
false

With only <section> specified, you can get a list of all variables in the section with their values that apply to the given URL. E.g

$ git config --get-urlmatch http https://weak.example.com
http.sslverify false

所有细节都在commit 6a56993b中:

http.<url>.*::

Any of the http.* options above can be applied selectively to some urls.
For a config key to match a URL, each element of the config key is compared to that of the URL, in the following order:

  • 方案(例如 https 中的 https://example.com/)。
  • 主机/域名(例如,example.comhttps://example.com/ 中)。
  • 端口号(例如 8080 中的 http://example.com:8080/)。
  • 路径(例如 repo.git 中的 https://example.com/repo.git )。
  • 用户名(例如 user 中的 https://user@example.com/repo.git )

The list above is ordered by decreasing precedence; a URL that matches a config key's path is preferred to one that matches its user name.
For example, if the URL is https://user@example.com/foo/bar a config key match of https://example.com/foo will be preferred over a config key match of https://user@example.com.

All URLs are normalized before attempting any matching (the password part, if embedded in the URL, is always ignored for matching purposes) so that equivalent urls that are simply spelled differently will match properly.

Environment variable settings always override any matches.
The urls that are matched against are those given directly to Git commands.
This means any URLs +visited as a result of a redirection do not participate in matching.

关于git - 只对某些 git url/域使用代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16067534/

相关文章:

git 冲突 : diff between BASE version and OTHER version

jenkins - 如何在 Jenkins 中使用可嵌入的构建状态插件获取分支特定的构建状态

ios - 检查 git diff 后,如何忽略一些我不想添加到此提交的文件中的更改?

android - GCM 推送通知不通过代理

git - 从提交 ID 中查找 git 分支或分支

git - 如果我的存储库中没有任何子模块,为什么 git 会说子项目是脏的?

node.js - Node.js 中如何处理 'read ETIMEDOUT'?

Java 代理不会将任何内容发送回浏览器

c - 对于 Eclipse CDT 项目,我需要从 Git 中遗漏什么

git - 如何使用 GitHub Actions 拒绝来自存储库成员的推送?