How to bypass the http.proxy that I have set using git config?



The work computer that I have, I occasionally carry it at home. Now, we have a proxy server at work, and I have configured git to use it by doing git config --global http.proxy So when I get back at home, I do not require a proxy, so I need to unset the http.proxy. This is okay if I have to do it once in a while, but right now I need to do this every day: set the proxy, when I get to work, go home and unset the proxy, next day set it at work again.

What I require

A way to bypass the http.proxy that has been set, individually in every command. Something like a --no-proxy option:

git --no-proxy pull

I do not want to specify the proxy in every command, like:

git --proxy=

because I do more gitting at work than I do at home.

Show source
| git   | proxy   2017-01-03 09:01 3 Answers

Answers to How to bypass the http.proxy that I have set using git config? ( 3 )

  1. 2017-01-03 10:01

    You can either do exactly what you asked by using

    git -c http.proxy= clone

    This will set the proxy to an empty value for this command and thus not use a proxy.

    If it is not about cloning, but about fetching, pushing, pulling and so on, you can also add two remotes to your repository and then set remote.<name>.proxy accordingly. Then you use one remote at work and the other at home. As the commits are the same you should not have to download a commit twice even if it is on different remote tracking branches.

  2. 2017-01-03 10:01

    I am not sure if it will suit your needs, but you can set up proxy for specific urls in such way:

    [http "<matching url>"]
        proxy = <url>

    For example: I am behind proxy at work and want to access projects on github, so I add following section to my ~/.gitconfig (note, that I use fake username "proxy" in matching url):

    [http ""]
        proxy =

    From now on, whenever I want to access any server without proxy - I do it as usual. When I want to access server over proxy, I add fake "proxy" username in front.

    This will stall when I am behind proxy, but work otherwise:

    $ git clone

    This will work behind proxy:

    $ git clone

    To make fetch, pull and push work - you will need to add 2 remotes (one for proxy, one without proxy) and use accordingly.

  3. 2017-01-03 10:01

    I solved a similar situation by writing a Bash script that simply turns the proxy on and off by setting the http.proxy configuration variable:

    if [[ $(git config --global http.proxy) ]]; then
        git config --global --unset http.proxy
        echo "Git is not using a proxy"
        git config --global http.proxy $proxy
        echo "Git is using the proxy at $proxy"

    I called the script flip_git_proxy and put it in the path. Now, each time I start a new Bash session I simply run:

    At work:

    $ flip_git_proxy
    Git is using the proxy at http://host:post

    At home:

    $ flip_git_proxy
    Git is not using a proxy

Leave a reply to - How to bypass the http.proxy that I have set using git config?

◀ Go back