Skip to content

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.

Copy link

rafaelblink commented Oct 24, 2017

Thank you bro. 👍

@jfach

This comment has been minimized.

Copy link

jfach commented Oct 30, 2017

+1

@luoxianginc

This comment has been minimized.

Copy link

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.

Copy link

qiaox commented Dec 3, 2017

It would be a big help.

@lolosssss

This comment has been minimized.

Copy link

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.

Copy link

Wiich0 commented Feb 13, 2018

+1

@enmanuelbasultom

This comment has been minimized.

Copy link

enmanuelbasultom commented Mar 1, 2018

Thaks it was really useful.

@fertab

This comment has been minimized.

Copy link

fertab commented Mar 8, 2018

Excelente! Muchas gracias! +1

@raja-kumar

This comment has been minimized.

Copy link

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.

Copy link

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.

Copy link

g3ngar commented Apr 24, 2018

Very handy gist! +1

@cytown

This comment has been minimized.

Copy link

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.

Copy link

AlbertoDePena commented Jun 6, 2018

Fantastic gist!!!

@wishma2013

This comment has been minimized.

Copy link

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.

Copy link

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.

Copy link

Bouzeghoub commented Jul 17, 2018

Thanks

@panchalkalpesh

This comment has been minimized.

Copy link

panchalkalpesh commented Jul 19, 2018

image

@fimars

This comment has been minimized.

Copy link

fimars commented Jul 24, 2018

Thanks !!

@oyyd

This comment has been minimized.

Copy link

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.

Copy link

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.

Copy link

ildixhaferri commented Aug 8, 2018

@aaroncalderon thank you!

@csJd

This comment has been minimized.

Copy link

csJd commented Aug 30, 2018

Thank you!

@jlrodriguezroldan

This comment has been minimized.

Copy link

jlrodriguezroldan commented Sep 3, 2018

Thanks.

@ttaylor29

This comment has been minimized.

Copy link

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.

Copy link

khoitv3 commented Sep 20, 2018

Thanks 👍

@st4ycool

This comment has been minimized.

Copy link

st4ycool commented Oct 15, 2018

What if proxy uses CA?

@sepehrHosseini

This comment has been minimized.

Copy link

sepehrHosseini commented Nov 12, 2018

@ryoldash

This comment has been minimized.

Copy link

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.

Copy link

Semen-kisliy commented Dec 17, 2018

thanks!

@amir5121

This comment has been minimized.

Copy link

amir5121 commented Dec 17, 2018

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

Yeeeaaaap.. Thanks

@fortuneM

This comment has been minimized.

Copy link

fortuneM commented Feb 8, 2019

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!

Thank you. it worked

@dipti219

This comment has been minimized.

Copy link

dipti219 commented Mar 21, 2019

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
It works.Thank you

@beraylik

This comment has been minimized.

Copy link

beraylik commented Mar 26, 2019

Hello what command I need to use to connect to local servers? I need to define no proxy for some URLs?

@foaudkajj

This comment has been minimized.

Copy link

foaudkajj commented Apr 9, 2019

Thanks :)

@ssnathan48

This comment has been minimized.

Copy link

ssnathan48 commented Apr 12, 2019

Hi All , i use azuredevops. None of these solutions are working for me. i tried sslVerify, http.proxy and proxy with domain and user name password. none works. Am i missing anything. what is the proxy server i would use? guess it is the proxy of my network. I used the one from wpad. i still get port 443 timed out error. Please help!!

@deepteshagrawal

This comment has been minimized.

Copy link

deepteshagrawal commented Apr 22, 2019

@ssnathan48: If you are using azuredevops and if you have setup personal token then you need to mention that token as proxy password instead of actual network proxy password. That works for me. It is something weired, but I am not able to find the reason for that. When I am changing password to actual network proxy password, then it stops working for me. So give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.