Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

git

proxy

Background

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 http://proxy.company.com. 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=http://proxy.company.com

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

like image 947
John Red Avatar asked Jan 03 '17 08:01

John Red


People also ask

How do I change my proxy settings in Git?

Setting the proxy for Git git config --global --add http. proxy http://USERNAME:PASSWORD@PROXY_ADDRESS:PROXY_PORT. git config --global --add https. proxy http://USERNAME:PASSWORD@PROXY_ADDRESS:PROXY_PORT.


3 Answers

You can either do exactly what you asked by using

git -c http.proxy= clone https://github.com/foo/bar.git

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.

like image 160
Vampire Avatar answered Nov 02 '22 23:11

Vampire


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 "https://[email protected]/"]
    proxy = https://10.144.1.10:8080/

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 https://github.com/project/path.git

This will work behind proxy:

$ git clone https://[email protected]/project/path.git

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

like image 28
Patryk Obara Avatar answered Nov 02 '22 23:11

Patryk Obara


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:

#!/bin/sh

proxy="http://host:port"

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

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
like image 43
Enrico Campidoglio Avatar answered Nov 03 '22 01:11

Enrico Campidoglio