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.

@aspaiva

This comment has been minimized.

Copy link

aspaiva commented May 4, 2019

My authentication problem occurs only in Visual Studio 2017/19, so I could not uninstall the 2015 version until now. I keep it just to synchronize the project. Some tip for me to configure the other versions of VS to work like 2015 do? Every git config works in 2015, but none of them work on newer versions. I am stuck here for a long time, and for endless reading the same topic, without a solution. Thanks in advance.

@obulmajon

This comment has been minimized.

Copy link

obulmajon commented Jun 1, 2019

how to delete "git config --global http.proxy"?

@obulmajon

This comment has been minimized.

Copy link

obulmajon commented Jun 1, 2019

Does commit or update global work together with the local network simultaneously?

@aemonge

This comment has been minimized.

Copy link

aemonge commented Jun 6, 2019

I usually push my .gitconfig to my repository, but obviously I can't since I have my user name and password plain texted in it.

Do you know any workarround for this ? Options in my head which I don't even know if it possible:

  • Apply a encription to the pass
  • Include the configuration of the proxy in a sperated files ( but I don't know how to join them later )
  • Force the usage of SSH instead of the HTTP . Since ssh security is way better
@evantoli

This comment has been minimized.

Copy link
Owner Author

evantoli commented Jun 7, 2019

Hey @aemonge, are you referring to the usernames and passwords for the proxy or for your Git repo?

If it is a corporate proxy between you and Git then I guess it depends on the proxy config as to whether or not they support SSH keys. I would start by asking the team/group that manages the proxy because it will need to be configured to associate your public SSH key with your account.

An alternative is to specify the proxy username and password for the repo in the global git config ~/.gitconfig instead of the repo config. This is done using the --global option as described in the Gist above.

If you were actually referring to your Git credentials, then both GitHub and Bitbucket support SSH keys for access, and IMHO is the easiest way to authenticate with a Git server:

@evantoli

This comment has been minimized.

Copy link
Owner Author

evantoli commented Jun 7, 2019

Hi @obulmajon, you can use the git config options below to unset/delete configuration. You can also simply the edit .gitconfig file.

From the git config man pages:

       --remove-section
           Remove the given section from the configuration file.
       --unset
           Remove the line matching the key from config file.
       --unset-all
           Remove all lines matching the key from config file.
@aemonge

This comment has been minimized.

Copy link

aemonge commented Jun 7, 2019

Hi @evantoli I'm referring to a corporate proxy..

So I have my dotFiles hosted in github, and one of them is my global ~/.gitconfig, so that I can always have my aliases available to me. But I also have the proxy configuration on that file, even though that's hasen't been pushed. Looking like this:

~/.gitconfig

/* ....... aliases and stuff .... */
[http]
proxy = http://username:password@http.proxy:8080/
sslVerify = false

As you can already see in my configuration, I was able to mask the IP address by changing my /etc/hosts file, but I have no idea how would I hide/mask my username and password, which are plain text.

Any ideas ? ( And sorry for being to short explaining my self initially )

Also, I realize this might not be the right channel since this is more of a unix configuration files issue; but I'm sure this is a common issue among the party of this gist xD

Thanks in advance !

@aspaiva

This comment has been minimized.

Copy link

aspaiva commented Jun 17, 2019

Thank you, once more!

@shaik1990

This comment has been minimized.

Copy link

shaik1990 commented Jul 16, 2019

what does leaving the empty for proxy server parameter means ?
git config --global http.proxy "" (Worked)

I tried git config --global http.proxy https://proxyuser:proxypwd@github.com:443 and it failed. (proxyuser=username, proxypwd=accesstoken) and it failed.

What is the main difference between leaving empty and having one, what is recommended way ? If I have to set up a proxy server then how should I?

Too many questions!! Thanks in advance.

@cgironda

This comment has been minimized.

Copy link

cgironda commented Jul 18, 2019

@evantoli

I just want to say thank you for showing us the code below:

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

I added sslVerify = false to my .gitconfig file and everything works nicely.

@garumaru

This comment has been minimized.

Copy link

garumaru commented Aug 9, 2019

Thanks for the guide!

May I ask if gitconfig support multiple proxy servers in case one is down?

Does it support something like below?
[http]
sslverify = false
proxy = http://proxy1
proxy = http://proxy2

@mutheusalmeida

This comment has been minimized.

Copy link

mutheusalmeida commented Aug 27, 2019

What worked for me:

$ git config --global http.proxy <address>:<port>

@rickysarraf

This comment has been minimized.

Copy link

rickysarraf commented Sep 6, 2019

Thank you. WOrked proper.

@minibrusp

This comment has been minimized.

Copy link

minibrusp commented Oct 3, 2019

**_

Thank you

_**

@sugunpradeep

This comment has been minimized.

Copy link

sugunpradeep commented Oct 11, 2019

Regarding git proxy settings via ssh. I could access my repository via https with the provided proxy settings. But could not access the same via ssh. Any suggestions Please.

@theasteve

This comment has been minimized.

Copy link

theasteve commented Oct 24, 2019

It looks as though this doesn't work for Github Pages. I'm able to push to a repo via git using this setting. However, I'm unable to deploy to Github. Is there information on how to Configure Github Pages to use a proxy?

@pamaxis

This comment has been minimized.

Copy link

pamaxis commented Nov 13, 2019

if having issues in Intellij IDEA and corp proxy try setting the system config as well as the global one:

git config --system http.proxy

:

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.