Configure Git to use with a proxy and switching back


Sometimes it can be useful and even necessary to configure Git to use a proxy in the global configuration.
It’s a easy as ( :
git config --global http.proxy host:port

This configuration will then be written in ~/.gitconfig.

You will then have something like that :

	name = Me
	email =
	proxy = host:port

Then one day you want to switch and use a different proxy, or none.

But it’s not obvious to configure, regarding the official documentation (

I could simply unset the proxy if I want to use none, like this :
git config --global --unset http.proxy

I also tried to create aliases to switch to another configuration, like :

  1. git config --global alias.proxy-local 'config --local http.proxy host:port'
  2. git config --global alias.noproxy-local 'config --local http.proxy none'

So I can use ‘git proxy-local’ or ‘git noproxy-local’ depending of the project.

But it could be more practical. By searching further I found a way to configure the proxy depending on the URL. Within the configuration we can use this format to configure options : http.<url>.* (
Some examples are also documented like this :

[http ""]
	sslVerify = false
	cookieFile = /tmp/cookie.txt

So that way you can configure a proxy by default, and for some URL use another proxy or none :

; Use a proxy by default
	proxy = host:port
; Use no proxy on internal server
[http "http://myserver.mycompany/"]
	proxy = 

That’s it !