ChatGPT解决这个技术问题 Extra ChatGPT

Git proxy bypass

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

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

An alternative is to use the SSH URL (instead of the HTTPS URL) to access Git repositories inside your company firewall. Any interaction with the repo using SSH will not attempt to go through the proxy.

J
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:

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

This edits the .git/config file in your working copy, which means that you would first need to clone the repository with the proxy unset. After cloning, you can reset the proxy, run the command as Jan posted, and then be able to pull and push without ever having to worry about it again.
I does not work, it still does connect to the proxy but without credentials.
seems to work fine for fetch, but not at all for "push", whereas the other answer with no_proxy=.my.domain works fine for push.
C
Community

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

export no_proxy=URLToIgnore

Where URLToIgnore is the URL that you want Git to ignore. You can also ignore URLs ending with a certain word.

export no_proxy=.mylocal

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

export no_proxy=.mylocal URLToIgnore

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

For more details: How to temporarily disable git http proxy


This is useful but does not mention the fact it's only valid for linux (and perhaps mac as well) but not for Windows. Would user's environment variables work the same way for git as .bash_profile?
This did not work for git on my iMac. The accepted answer worked for git on my iMac.
You can do same in Windows. Add an environment variable 'no_proxy' with value of URLS_to_Ignore. Don't forget to start a new CMD shell. Or to get working in current CMD just set no_proxy=URLS_to_Ignore. Macs should work just same as *nix. Don't forget to start a new shell terminal (or source ~/.bash_profile if the changes added to that).
V
VonC

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

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)

See commit c846664 (tanayabh)

make config --add behave correctly for empty and NULL values

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 --add in 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 NULL values in matches() in config.c.


Thanks for the detailed reply!
G
Ganesh Pendyala

For Windows users

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

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.


O
OriginalHacker

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

$> 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.

$> 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.

I would put the following line last in .bashrc

export no_proxy=$no_proxy,<your repo>

I hope that makes things clearer!


R
Riddhi Sanyal

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

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.

Hope this helps.


d
daniel sp

If you are trying to clone a new repo, some solutions given in other answers will fail, because git complains that the local folder contains no git repository.

In this case this worked for me

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

C
Christo

Old question but here is how to configure this globally:

Set the proxy:

git config --global http.proxy proxy.example.com:3128

Turn off the proxy for specific URLs by setting the their proxy to the empty string (replace myserver.localdomain with your server FQDN):

git config --global http.https://myserver.localdomain.proxy ''

S
Shawn Mehan

just execute below command on command prompt

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