是否可以将 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.com
在https://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 ishttps://user@example.com/foo/bar
a config key match ofhttps://example.com/foo
will be preferred over a config key match ofhttps://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/