Git 代理绕过

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16538372/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:09:16  来源:igfitidea点击:

Git proxy bypass

githttpproxy

提问by yannisf

Git works in a proxied environment by setting the http.proxy configuration parameter.

Git 通过设置 http.proxy 配置参数在代理环境中工作。

For certain addresses I need to bypass the proxy. Is there a no-proxy/bypass-proxy configuration parameter?

对于某些地址,我需要绕过代理。是否有 no-proxy/bypass-proxy 配置参数?

回答by Jan Gutvirth

The proxy can be overridden on a per-remote basis - see http://git-scm.com/docs/git-config(look for the "http.proxy" and "remote.<name>.proxy" settings). Assuming you have the remote called "origin" then the command you could use to bypass proxy for this remote is:

可以在每个远程的基础上覆盖代理 - 请参阅http://git-scm.com/docs/git-config(查找“http.proxy”和“remote.<name>.proxy”设置)。假设你有一个名为“origin”的遥控器,那么你可以用来绕过这个遥控器的代理的命令是:

git config --add remote.origin.proxy ""

回答by Yas T.

To bypass proxy for certain, usually a local address, all you need to do is:

要绕过某些代理,通常是本地地址,您需要做的就是:

export no_proxy=URLToIgnore

Where URLToIgnoreis the URL that you want Gitto ignore. You can also ignore URLs ending with a certain word.

URLToIgnore您要Git忽略的 URL在哪里。您还可以忽略以某个单词结尾的 URL。

export no_proxy=.mylocal

Where all urls ending with .mylocalwill get ignored. To ignore multiple URLs:

所有以 结尾的网址.mylocal都将被忽略。要忽略多个 URL:

export no_proxy=.mylocal URLToIgnore

To make it permanent, add it to your ~/username/.bash_profilefile. If you cannot find .bash_profilefile in your user root directory, then manually create it.

要使其永久化,请将其添加到您的~/username/.bash_profile文件中。如果.bash_profile在用户根目录中找不到文件,请手动创建它。

For more details: How to temporarily disable git http proxy

更多详情: 如何暂时禁用 git http 代理

回答by VonC

Make sure you have a Git 2.1.2+ if you want to set a config to an empty value, like

如果要将配置设置为空值,请确保您有 Git 2.1.2+,例如

git config --add remote.origin.proxy ""

Because if you decide to restore a proxy for that remote (here 'origin')... it will segfault with a Git older than 2.1.2 (Sept. 30th, 2014)

因为如果您决定恢复该远程的代理(此处为“ origin”)...它将使用早于 2.1.2 的 Git(2014 年 9 月 30 日)出现段错误

See commit c846664(tanayabh)

提交 c846664( tanayabh)

make config --addbehave correctly for empty and NULLvalues

make config --add对空和NULL值的行为正确

Currently if we have a config file like,

目前,如果我们有一个像这样的配置文件,

[foo]
        baz
        bar =

and we try something like, "git config --add foo.baz roll", Git will segfault. Moreover, for "git config --add foo.bar roll", it will overwrite the original value instead of appending after the existing empty value.

The problem lies with the regexp used for simulating --addin git_config_set_multivar_in_file(), "^$", which in ideal case should not match with any string but is true for empty strings.
Instead use a regexp like "a^" which can not be true for any string, empty or not.

For removing the segfault add a check for NULLvalues in matches()in config.c.

我们尝试诸如“ git config --add foo.baz roll”之类的东西,Git 会出现段错误。此外,对于“ git config --add foo.bar roll”,它将覆盖原始值而不是附加在现有的空值之后。

问题在于用于模拟--addin git_config_set_multivar_in_file(), " ^$" 的正则表达式,在理想情况下,它不应该与任何字符串匹配,但对于空字符串是正确的。
而是使用像 " a^" 这样的正则表达式,对于任何字符串,无论是否为空,都不能为真。

要删除段错误,请添加对NULLinmatches()中的值的检查config.c

回答by Ganesh Pendyala

Accepted answerrequires the git repo to exist before hand to work and the second best answerworks only for linux & Mac. So in windows to make it work for https://git-url.com/project/repo-name.gittry the following in a command prompt

接受的答案要求 git repo 在工作之前存在,第二个最佳答案仅适用于 linux 和 Mac。因此,在 Windows 中使其适用于https://git-url.com/project/repo-name.git在命令提示符中尝试以下操作

set no_proxy=git-url.com

then

然后

git clone git-url.com/repo-name.git

Now you will have a repo to apply the accepted answer.

现在您将有一个回购来应用接受的答案。

回答by Riddhi Sanyal

Due to Windows / Unix user role, if you can't eliminate the http_proxy from command line, please try this approach -

由于 Windows / Unix 用户角色,如果您无法从命令行消除 http_proxy,请尝试这种方法 -

git config -l --show-origin

That will print the configurations based present on the files according to hierarchy. Now go to specific file (local .git/config folder file) and update / remove the http_proxy.

这将根据层次结构打印基于文件的配置。现在转到特定文件(本地 .git/config 文件夹文件)并更新/删除 http_proxy。

Hope this helps.

希望这可以帮助。

回答by OriginalHacker

Assuming you are starting by cloning, the origin-config things are not so useful. When I find myself in that position I do.

假设您从克隆开始,那么 origin-config 的东西就没有那么有用了。当我发现自己处于那个位置时,我会这样做。

$> no_proxy=$no_proxy,<git-url|ip> git clone ...

Note that this will be per command. To make this permanent for the repo just cloned, you can now go to the newly cloned repo and add the empty-proxy setting.

请注意,这将是每个命令。要使刚刚克隆的 repo 永久存在,您现在可以转到新克隆的 repo 并添加空代理设置。

$> git config --add remote.origin.proxy ""

However, if you want this host or IP excluded from proxy in all cases, use your shells init-file to do the inclusion of your origins permanent for your user.

但是,如果您希望在所有情况下都从代理中排除此主机或 IP,请使用您的 shell 初始化文件为您的用户永久包含您的来源。

I would put the following line last in .bashrc

我会将以下行放在 .bashrc 的最后一行

export no_proxy=$no_proxy,<your repo>

I hope that makes things clearer!

我希望这能让事情更清楚!

回答by Dheeraj Pure

just execute below command on command prompt

只需在命令提示符下执行以下命令

git config --global http.proxy [Proxy IP]:[Proxy port]