只使用代理某些giturl/域名?
有没有可能configurationgit只为特定的域使用代理?
我想使用我们的公司代理来访问Github,但离开它访问我们自己的内部git回购。
我正在使用鲍尔,它需要我们的防火墙和github内的项目,所以我不能这样做,作为一个项目设置。 它需要是某种全局configuration选项。 有什么想法吗?
我通常使用环境variables:
http_proxy=http://username:password@proxydomain:port-
https_proxy=http://username:password@proxydomain:port
在访问GitHub仓库时,这是由git拾取的。
注意:
-
http_proxy和https_proxy必须使用代理的http://url(无https://)。 - 总是使用
proxydomain的fqn(全限定名) (不要依赖它的简称)
但是对于内部回购,我所要做的就是定义并导出一个更多的环境variables:
-
no_proxy=.my.company,localhost,127.0.0.1,::1,用于访问任何类似myrepo.my.company或localhost的地址。
你可以定义NO_PROXY或no_proxy ,没关系。
但为了以防万一,我总是设置HTTP_PROXY , HTTPS_PROXY , http_proxy , https_proxy , NO_PROXY和no_proxy 。
为了增加另一种可能性,你可以通过git config http.proxy定义一个代理 。
git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:proxyport
但真正干净的是, 从git1.8.5(2013年10月)开始 ,您可以设置每个url的http设置 。
现在可以根据configuration适用的URL指定“ http.* ”variables 。
例如,
[http] sslVerify = true [http "https://weak.example.com/"] sslVerify = false
只有在与指定的站点通话时
http.sslVerifyclosureshttp.sslVerify。
参见提交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
如果只指定
<section>,则可以使用适用于给定URL的值获取该部分中所有variables的列表。 例如
$ git config --get-urlmatch http https://weak.example.com http.sslverify false
所有的细节在提交6a56993b :
http.<url>.*::
上面的任何http。*选项都可以select性地应用于某些url。
要使configuration键与URL匹配,configuration键的每个元素都将按照以下顺序与URL的元素进行比较:
- Scheme (例如
https中的https://example.com/)。 - 主机/域名 (例如
https://example.com/example.com)。 - 端口号码 (例如,
http://example.com:8080/:8080中的8080)。 - path (例如
https://example.com/repo.gitrepo.git)。 - 用户名 (例如
https://user@example.com/repo.gituser)
上面的列表按优先顺序排列; 与configuration键path相匹配的URL优先于与其用户名匹配的URL。
例如,如果URL是https://user@example.com/foo/bar,则https://example.com/foo的configuration密钥匹配优于https://user@example.com的configuration密钥匹配https://user@example.com。在尝试任何匹配之前,所有的URL都被标准化(如果embedded在URL中,则密码部分总是被忽略以便于匹配),以便简单拼写不同的等效URL将正确匹配。
环境variables设置总是覆盖任何匹配 。
匹配的url是直接给Git的命令。
这意味着任何由于redirect而访问的URL都不参与匹配。
正如一些人在这里提到的,你可以通过指定一个URL和代理设置来做到这一点,但是这里有一个用例来解决这个问题。 感谢上面的VonC!
注意下面,我指定了Git服务器的根目录。 你已经克隆的git仓库的完整path不是必需的。 您可以使用单个条目来照顾整个服务器。
将以下内容添加到.gitconfig文件中。 在我的Windows系统上,我正在使用%userprofile%\。gitconfig
[http] proxy = http://my.proxy.net:8080 [https] proxy = http://my.proxy.net:8443 [http "http://my.internalgitserver.com/"] proxy = ""
您可以专门为每个远程调整各种configuration选项。 假设我们有两个遥控器,分别命名为origin和upstream 。 您调整每个代理进行以下操作:
git config --path remote.origin.proxy http://user:pass@proxy_for_origin:8080 git config --path remote.upstream.proxy http://user:pass@proxy_for_upstream:8080
这将改变本地存储库configuration( .git/config )中每个远程的部分。
您也可以根据需要调整全局configuration选项。 由于在全局configuration文件( $HOME/.gitconfig )中引用远程名称没有意义,所以可以使用url匹配 (IIRC,自从Git 1.8.5以后支持)。 例:
[http "https://example.com/repo1.git"] proxy = http://user:pass@proxy1:8080 [http "https://example.com/repo2.git"] proxy = http://user:pass@proxy2:8080
如果你想看看已经设置了什么:
git config --path --get-urlmatch https://example.com/repo1.git git config --path --get-urlmatch https://example.com/repo2.git
在Windows上,只需[注意无密码]以下为我工作
git config --global http.proxy http://mydomain\\myusername:@myproxyserver:proxyport git config --global https.proxy http://mydomain\\myusername:@myproxyserver:proxyport