仅对某些git URL/域使用代理?
是否可以将git配置为仅对特定域使用代理 我想使用我们的公司代理来访问Github,但在访问我们自己的内部git回购协议时不要使用它仅对某些git URL/域使用代理?,git,github,proxy,Git,Github,Proxy,是否可以将git配置为仅对特定域使用代理 我想使用我们的公司代理来访问Github,但在访问我们自己的内部git回购协议时不要使用它 我使用的是bower,它需要在防火墙和github上都有项目,所以我不能按项目设置这样做。它需要某种全局配置选项。有什么想法吗?我通常使用环境变量: http\u代理=http://username:password@代理域:端口 https\u代理=http://username:password@代理域:端口 这是git在访问GitHub repo时获取的
我使用的是bower,它需要在防火墙和github上都有项目,所以我不能按项目设置这样做。它需要某种全局配置选项。有什么想法吗?我通常使用环境变量:
http\u代理=http://username:password@代理域:端口
https\u代理=http://username:password@代理域:端口
和http\u proxy
都必须使用代理的https\u proxy
url(无http://
)https://
- 始终使用
(不要依赖其短名称)proxydomain
,用于访问地址类似于no_proxy=.my.company,localhost,127.0.0.1,::1
或localhost的任何回购协议myrepo.my.company
无代理
或无代理
,这无关紧要
但为了以防万一,我总是设置
HTTP\u PROXY
,HTTPS\u PROXY
,HTTP\u PROXY
,HTTPS\u PROXY
,NO\u PROXY
和NO\u PROXY来添加另一种可能性,您可以
但真正巧妙的是,您可以为每个url设置http设置
现在可以根据配置应用的每个URL指定“http.
”变量
比如说,
[http]
sslVerify = true
[http "https://weak.example.com/"]
sslVerify = false
只有在与指定站点通话时才会关闭http.sslVerify
见:
只需指定
,您就可以获得节中所有变量的列表,以及应用于给定URL的值。例如
详情载于:
http..*::
上述任何http.*选项都可以选择性地应用于某些URL。
为了使配置键与URL匹配,将按照以下顺序将配置键的每个元素与URL的每个元素进行比较:
- 方案(例如
https://example.com/
)
- 主机/域名(例如
example.com中的https://example.com/
)
- 端口号(例如
8080中的http://example.com:8080/
)
- 路径(例如
inhttps://example.com/repo.git
)李>
- 用户名(例如
https://user@example.com/repo.git
)
上面的列表按优先级递减排序;与配置键路径匹配的URL优先于与其用户名匹配的URL。
例如,如果URL是https://user@example.com/foo/bar
https://example.com/foo
将优先于配置键匹配https://user@example.com
在尝试任何匹配之前,所有URL都会进行规范化(如果在URL中嵌入了密码部分,则出于匹配目的,将始终忽略密码部分),以便拼写不同的等效URL能够正确匹配
环境变量设置始终覆盖所有匹配项匹配的URL是直接提供给Git命令的URL。
这意味着由于重定向而访问的任何URL+都不会参与匹配
在Windows上,简单的[无密码的便笺]对我来说很有效
git config --global http.proxy http://mydomain\\myusername:@myproxyserver:proxyport
git config --global https.proxy http://mydomain\\myusername:@myproxyserver:proxyport
您可以针对每个遥控器调整各种配置选项。假设我们有两个遥控器,分别命名为
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
这将更改本地存储库中每个远程存储库的配置(.git/config
)
如果愿意,您还可以调整全局配置选项。由于在全局配置文件($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
正如一些人在这里提到的,您可以通过指定URL和代理设置来实现这一点,但下面的用例为我解决了这个问题。感谢上面的VonC 请注意,下面我指定的是Git服务器的根。您克隆的git回购的完整路径不是必需的。您可以使用单个条目来管理整个服务器 将以下内容添加到.gitconfig文件中。在我的windows系统上,我正在使用%userprofile%\.gitconfig
[http]
proxy = http://my.proxy.net:8080
[https]
proxy = http://my.proxy.net:8443
[http "http://my.internalgitserver.com/"]
proxy = ""
我有一个类似的问题,我支持我的公司代理。我基本上有两种存储库:
git config --global --add http.proxy "http://username:password@proxydomain:port"
git config --global --add https.proxy "https://username:password@proxydomain:port"
然后移动到包含.git文件夹且不需要代理的本地目录
cd "C:\Users\username\directory_without_proxy\"
使用空代理设置本地配置
git config --local --add http.proxy ""
git config --local --add https.proxy ""
也可以用另一种方式。也就是说,使用代理设置将全局配置保持为空,将本地配置保持为空
只需再次检查,您可以使用以下命令分别列出全局和本地的配置设置:
git config --global --list
git config --local --list
假设您的代理是(就像我的ss
)是:socks5://127.0.0.1:1086
配置git代理
- 总的来说
- 添加:
git配置--全局http.proxy socks5:
git config --global --add http.proxy "http://username:password@proxydomain:port" git config --global --add https.proxy "https://username:password@proxydomain:port"
cd "C:\Users\username\directory_without_proxy\"
git config --local --add http.proxy "" git config --local --add https.proxy ""
git config --global --list git config --local --list
- 添加: