仅对某些 git url/域使用代理? [英] Only use a proxy for certain git urls/domains?

查看:22
本文介绍了仅对某些 git url/域使用代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to configure git to use a proxy only for specific domains?

我想使用我们的公司代理访问 Github,但不使用它来访问我们自己的内部 git 存储库.

I'd like to use our corporate proxy to access Github but leave it off for accessing our own internal git repos.

我正在使用 bower,它需要在我们的防火墙内和 github 上都需要项目,因此我无法按照每个项目设置执行此操作.它需要是某种全局配置选项.有什么想法吗?

I'm using bower and it needs to require items both within our firewall and on github so I can't do this as a per project setting. It needs to be some kind of global configuration option. Any thoughts?

推荐答案

我通常使用环境变量:

  • http_proxy=http://username:password@proxydomain:port
  • https_proxy=http://username:password@proxydomain:port

在访问 GitHub 存储库时由 git 获取.

That is picked up by git when accessing GitHub repo.

注意:

  • http_proxyhttps_proxy 都必须使用代理的 http:// url(没有 https://).
  • 始终使用 proxydomainfqn(完全限定名称)(不要依赖它的简称)
  • both http_proxy and https_proxy must use the http:// url of the proxy (no https://).
  • always use the fqn (full qualified name) of proxydomain (don't rely on its short name)

但是对于内部存储库,我所要做的就是定义并导出另一个环境变量:

But for internal repo, all I have to do is define and export one more environment variable:

  • no_proxy=.my.company,localhost,127.0.0.1,::1,用于访问具有类似 myrepo.my.company 或 localhost 的地址的任何存储库.
  • no_proxy=.my.company,localhost,127.0.0.1,::1, for accessing any repo with an address like myrepo.my.company or localhost.

您可以定义NO_PROXYno_proxy,没关系.

You can define NO_PROXY or no_proxy, it doesn't matter.

但为了以防万一,我总是设置HTTP_PROXYHTTPS_PROXYhttp_proxyhttps_proxyNO_PROXYno_proxy.

But just in case, I always set HTTP_PROXY, HTTPS_PROXY, http_proxy, https_proxy, NO_PROXY and no_proxy.

这篇关于仅对某些 git url/域使用代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆