Instantly share code, notes, and snippets.

Embed
What would you like to do?
Configure Git to use a proxy

Configure Git to use a proxy

##In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port

Or for a specific domain, something like:

git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port
git config --global http.https://domain.com.sslVerify false

Setting http.<url>.sslVerify to false may help you quickly get going if your workplace employs man-in-the-middle HTTPS proxying. Longer term, you could get the root CA that they are applying to the certificate chain and specify it with either http.sslCAInfo or http.sslCAPath.

See also the git-config documentation, especially the following sections if you're having HTTPS/SSL issues

  • http.sslVerify
  • http.sslCAInfo
  • http.sslCAPath
  • http.sslCert
  • http.sslKey
  • http.sslCertPasswordProtected

In Detail

Configure the proxy

You can configure these globally in your user ~/.gitconfig file using the --global switch, or local to a repository in its .git/config file.

Setting a global proxy

Configure a global proxy if all access to all repos require this proxy

git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port

URL specific proxy

If you wish to specify that a proxy should be used for just some URLs that specify the URL as a git config subsection using http.<url>.key notation:

git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port

Which will result in the following in the ~/.gitconfig file:

[http]
[http "https://domain.com"]
	proxy = http://proxyUsername:proxyPassword@proxy.server.com:port

Handle subsequent SSL protocol errors

If you're still having trouble cloning or fetching and are now getting an unable to access 'https://...': Unknown SSL protocol error in connection to ...:443 then you may decide to switch off SSL verification for the single operation by using the -c http.sslVerify=false option

git -c http.sslVerify=false clone https://domain.com/path/to/git

Once cloned, you may decide set this for just this cloned repository's .git/config by doing. Notice the absence of the --global

git config http.sslVerify false

If you choose to make it global then limit it to a URL using the http.<url>.sslVerify notation:

git config --global http.https://domain.com.sslVerify false

Which will result in the following in the ~/.gitconfig file:

[http]
[http "https://domain.com"]
	proxy = http://proxyUsername:proxyPassword@proxy.server.com:port
	sslVerify = false

Show current configuration

To show the current configuration of all http sections

git config --global --get-regexp http.*

If you are in a locally cloned repository folder then you drop the --global and see all current config:

git config --get-regexp http.*

Unset a proxy or SSL verification

Use the --unset flag to remove configuration being specific about the property -- for example whether it was http.proxy or http.<url>.proxy. Consider using any of the following:

git config --global --unset http.proxy
git config --global --unset http.https://domain.com.proxy

git config --global --unset http.sslVerify
git config --global --unset http.https://domain.com.sslVerify

@rafaelblink

This comment has been minimized.

rafaelblink commented Oct 24, 2017

Thank you bro. 👍

@jfach

This comment has been minimized.

jfach commented Oct 30, 2017

+1

@luoxianginc

This comment has been minimized.

luoxianginc commented Nov 19, 2017

I set a http.proxy , but keep getting "proxy CONNECT error" with any https URL immediately, even the fake ones like "https://a.com", does anyone know what this is about? My git version is 2.14.3, then I switch to 1.8.3 and it works.

@qiaox

This comment has been minimized.

qiaox commented Dec 3, 2017

It would be a big help.

@lolosssss

This comment has been minimized.

lolosssss commented Jan 24, 2018

After multiple times set/unset proxy, I find many duplicated [http],[https] in ~/.gitconfig . How could I prevent this? Thank you.

@Wiich0

This comment has been minimized.

Wiich0 commented Feb 13, 2018

+1

@enmanuelbasultom

This comment has been minimized.

enmanuelbasultom commented Mar 1, 2018

Thaks it was really useful.

@fertab

This comment has been minimized.

fertab commented Mar 8, 2018

Excelente! Muchas gracias! +1

@raja-kumar

This comment has been minimized.

raja-kumar commented Mar 11, 2018

in the command 'git config --global http.proxy http://proxyUsername:proxyPassword@proxy.server.com:port', what are proxyUsername and proxyPassword?

@aaroncalderon

This comment has been minimized.

aaroncalderon commented Mar 15, 2018

@raja-kumar If you are behind a Corporate Proxy, those would be the User Name and Password you use to log in to your workstation.

@g3ngar

This comment has been minimized.

g3ngar commented Apr 24, 2018

Very handy gist! +1

@cytown

This comment has been minimized.

cytown commented May 14, 2018

Hi, could you please give me a manual for https proxy in git config?

@AlbertoDePena

This comment has been minimized.

AlbertoDePena commented Jun 6, 2018

Fantastic gist!!!

@wishma2013

This comment has been minimized.

wishma2013 commented Jun 6, 2018

My proxy server has just address and port and password, but no username?Then how to config proxy?Use my local address or my proxy server address?If local address,what's the port?

@allanpoulsen

This comment has been minimized.

allanpoulsen commented Jul 9, 2018

A little comment: use socks:// instead of http:// if you are using a socks5 proxy. Thanks for the Gist!

@Bouzeghoub

This comment has been minimized.

Bouzeghoub commented Jul 17, 2018

Thanks

@panchalkalpesh

This comment has been minimized.

panchalkalpesh commented Jul 19, 2018

image

@fimars

This comment has been minimized.

fimars commented Jul 24, 2018

Thanks !!

@oyyd

This comment has been minimized.

oyyd commented Jul 29, 2018

Git may not use http.proxy when the remote settings are with git:// protocol.

@Ambssharma

This comment has been minimized.

Ambssharma commented Aug 4, 2018

In this command "git config --global http.https://domain.com.proxy http://proxyUsername:proxyPassword@proxy.server.com:port "... what is proxy.server.com???

@ildixhaferri

This comment has been minimized.

ildixhaferri commented Aug 8, 2018

@aaroncalderon thank you!

@csJd

This comment has been minimized.

csJd commented Aug 30, 2018

Thank you!

@jlrodriguezroldan

This comment has been minimized.

jlrodriguezroldan commented Sep 3, 2018

Thanks.

@ttaylor29

This comment has been minimized.

ttaylor29 commented Sep 11, 2018

git config --global http.proxy myproxy.com:8080

what would "myproxy.com" be in my case?

ANSWER:

This worked for me:

git config --global http.proxy ""

So I guess you can leave it empty!

@khoitv3

This comment has been minimized.

khoitv3 commented Sep 20, 2018

Thanks 👍

@st4ycool

This comment has been minimized.

st4ycool commented Oct 15, 2018

What if proxy uses CA?

@sepehrHosseini

This comment has been minimized.

sepehrHosseini commented Nov 12, 2018

@ryoldash

This comment has been minimized.

ryoldash commented Dec 14, 2018

$git config --global http.proxy http://mydomain.com:port
worked for me. Thanks.

@Semen-kisliy

This comment has been minimized.

Semen-kisliy commented Dec 17, 2018

thanks!

@amir5121

This comment has been minimized.

amir5121 commented Dec 17, 2018

Git may not use http.proxy when the remote settings are with git:// protocol.

Yeeeaaaap.. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment