如何暂时禁用 git http 代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19523903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to temporarily disable git http proxy
提问by David
I am using git behind a corporate firewall, and I am successfully cloning external projects by using the http.proxy --global config.
我在公司防火墙后面使用 git,并且我通过使用 http.proxy --global 配置成功克隆了外部项目。
My problem arises when I want to clone through http on the intranet. I suspect that the proxy config interferes with the intranet request.
当我想通过内网上的http进行克隆时,出现了我的问题。我怀疑代理配置干扰了内网请求。
I know I could reset the config before using the intranet, but that is not very user friendly.
我知道我可以在使用 Intranet 之前重置配置,但这对用户来说不是很友好。
I also saw this answer, but it seems to apply only to an existing repository.
我也看到了这个答案,但它似乎只适用于现有的存储库。
Is there a way to deactivate the proxy usage only for one command invocation? In this case, the initial clone?
有没有办法只为一个命令调用停用代理使用?在这种情况下,最初的克隆?
回答by VonC
I always set:
我总是设置:
no_proxy=.mycompany
(export
if I am on Unix, or a simple set
on Windows)
(export
如果我在 Unix 上,或者set
在 Windows 上简单)
It is enough to bypass the proxy for all intranet url ending with ".mycompany
".
绕过所有以“ .mycompany
”结尾的内网url的代理就足够了。
See for an example:
参见示例:
- "Can't update/install using composer behind a corporate firewall"
- "Only use a proxy for certain git urls/domains?"
- "Cannot do
git-svn fetch
behind proxy"
I use it in my own project: .proxy.example
:
我在我自己的项目中使用它.proxy.example
::
export http_proxy=http://username:[email protected]:port
export https_proxy=http://username:[email protected]:port
export no_proxy=.company localhost
回答by thdoan
What I like to do is set two Git aliases:
我喜欢做的是设置两个 Git 别名:
~/.gitconfig
~/.gitconfig
[alias]
noproxy = config --global --remove-section http
proxy = config --global http.proxy http://127.0.0.1:9666
Note that I didn't use config --global --unset http.proxy
to reset the proxy because that leaves behind the [http]
section heading, so after repeatedly enabling and disabling the proxy your .gitconfig
will be polluted with a bunch of empty [http]
section headings. No big deal, but it's just annoying.
请注意,我没有使用config --global --unset http.proxy
过重置代理,因为这会留下[http]
部分标题,因此在反复启用和禁用代理后,您.gitconfig
将被一堆空的[http]
部分标题污染。没什么大不了的,只是很烦人。
In some cases, such as behind corporate firewalls, you need to configure ~/.ssh/config
instead. The setup becomes slightly more complicated:
在某些情况下,例如在公司防火墙后面,您需要进行配置~/.ssh/config
。设置变得稍微复杂一些:
~/.gitconfig
~/.gitconfig
[alias]
noproxy = !sh -c 'cp ~/.ssh/config.noproxy ~/.ssh/config'
proxy = !sh -c 'cp ~/.ssh/config.proxy ~/.ssh/config'
~/.ssh/config.noproxy
~/.ssh/config.noproxy
Host github.com-username
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
~/.ssh/config.proxy
~/.ssh/config.proxy
Host *
ProxyCommand connect -H 127.0.0.1:9666 %h %p
Host github.com-username
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
You can even combine the two methods by changing the aliases to this:
您甚至可以通过将别名更改为以下方式来组合这两种方法:
[alias]
noproxy = !sh -c 'git config --global --remove-section http 2> /dev/null && cp ~/.ssh/config.noproxy ~/.ssh/config'
proxy = !sh -c 'git config --global http.proxy http://127.0.0.1:9666 && cp ~/.ssh/config.proxy ~/.ssh/config'
Now I can simply type git noproxy
to disable the proxy and git proxy
to enable it. You can even switch among multiple proxies by creating more aliases.
现在我可以简单地键入git noproxy
以禁用代理并git proxy
启用它。您甚至可以通过创建更多别名在多个代理之间切换。
回答by bimalmampatta
In my case, I was able to disable git clone requests going through the proxy in my corporate setting by executing
就我而言,我能够通过执行在我的公司设置中禁用通过代理的 git clone 请求
git config --global --add remote.origin.proxy ""
git config --global --add remote.origin.proxy ""
As per the git documentation, this disables all requests to that remote repo named origin.
根据 git 文档,这会禁用对名为 origin 的远程存储库的所有请求。