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

@minibrusp
Copy link

minibrusp commented Oct 3, 2019

**_

Thank you

_**

@sugunpradeep
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
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
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

:

@freifrauvonbleifrei
Copy link

freifrauvonbleifrei commented Dec 19, 2019

@ people looking for an ssh solution: this here worked for me

@sidd3sh
Copy link

sidd3sh commented Jan 8, 2020

Thank you!

@chenrq2005
Copy link

chenrq2005 commented Jan 30, 2020

Thanks! Great job! It worked for me.

@atulkumarpccs
Copy link

atulkumarpccs commented Feb 6, 2020

Great this resolves my problem :)

@ozbillwang
Copy link

ozbillwang commented Feb 12, 2020

https://gist.github.com/ozbillwang/005bd1dfc597a2f3a00148834ad3e551

@freifrauvonbleifrei

Thanks, the original solution is only for https access to github which is not good enough. Because you have to provide github username and password everytime, when you try to git push later.

If we need support ssh+git access, your way works.

Sample clone commands:

The clone command with protocol https

git clone https://github.com/kubernetes/kubernetes.git

The clone command with protocol ssh+git

git clone git@github.com:kubernetes/kubernetes.git

Notes:

If you only need access github by the way of ssh+git, you needn't set any proxy in ~/.gitconfig and run git config --global http.proxy ... and similar commands at all

Work with ssh config

So I have to set ssh config (~/ssh/config) with ProxyCommand properly, git clone start working with proxy.

Host github.com
    Hostname github.com
    ServerAliveInterval 55
    ForwardAgent yes
    ProxyCommand /usr/bin/corkscrew <replace_with_your_company_proxy_server> <3128> %h %p ~/.ssh/myauth

Work with http/https

update ~/.gitconfig

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

sslVerify setting is not necessary.

@dalegaspi
Copy link

dalegaspi commented Mar 27, 2020

this has been useful information for me during this pandemic. thank you.

@duangsuse
Copy link

duangsuse commented Apr 11, 2020

Thank you <3

@kvnloughead
Copy link

kvnloughead commented Apr 12, 2020

Thank you, @dipti219. I was having trouble figuring out how to fill in the blanks. When in doubt, don't!

@MaratZakirov
Copy link

MaratZakirov commented May 27, 2020

Can I use this method to use git on server (to which I connect via VPN + SSH) which does not have internet access?

@csmper
Copy link

csmper commented Jun 18, 2020

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 !

This was helpful to resolve my issue +1

@xiaoliuzi
Copy link

xiaoliuzi commented Aug 8, 2020

Before clone code, set proxy in terminal.:)

git config --global http.proxy 'socks5://127.0.0.1:1080' 
git config --global https.proxy 'socks5://127.0.0.1:1080'

@Janice9399
Copy link

Janice9399 commented Nov 23, 2020

git config --global http.proxy ""

It helps a lot. Thanks

@ahanafi
Copy link

ahanafi commented Dec 8, 2020

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!

Thanks, it worked in my machine :D

@swarnalatha116
Copy link

swarnalatha116 commented Apr 3, 2021

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!

This Worked for me:
git config --global http.proxy ""
git config --global https.proxy ""

Thanks

@lilduckyboi
Copy link

lilduckyboi commented Apr 9, 2021

does anyone know how i can get this?

@leensabbouh
Copy link

leensabbouh commented Jun 28, 2021

thank u

@HosseinMohammadii
Copy link

HosseinMohammadii commented Jul 20, 2021

thanks bro

@taozuhong
Copy link

taozuhong commented Aug 9, 2021

export http_proxy=127.0.0.1:8080
export https_proxy=127.0.0.1:8080

@refayathaque
Copy link

refayathaque commented Sep 14, 2021

This has been immensely helpful for me and my team, thank you so much :)

@xundeenergie
Copy link

xundeenergie commented Nov 12, 2021

I use a long time this solution... but with a big stomach pain... my credentials are in cleartext stored...

Usually i store all my passworts with pass. The standard unix password-manager. So i can call my passwords on shell with
pass show key
and it returns the password for key to stdout.

Now i need a possibility to call this everytime, git uses the proxy.
The pseudocode is:

[http "https://github.com"]
	proxy = http://proxyUsername:$(pass show github)@proxy.server.com:port
	sslVerify = false

How can i run a system-call in git at THIS specific place?

@LittleControl
Copy link

LittleControl commented Nov 26, 2021

Thanks a lot

@nagarajasr
Copy link

nagarajasr commented Nov 29, 2021

my repo remote origin url contains a username and password for the repo. in this case, the global proxy configuration which is domain based does not work. any suggestions if a wildcard can be used?

https.https://git.mydomain.com.proxy=http://proxyUser:proxyPass@proxyServer.com:proxyPort
remote.origin.url=https://gitUsername:gitPassword@git.mydomain.com/scm/myproject/myrepo

@ahdung
Copy link

ahdung commented Dec 21, 2021

How to auto follow IE proxy?

@Hanjingxue-Boling
Copy link

Hanjingxue-Boling commented Feb 6, 2022

Thanks for this documentation!
💖🎉

@yonoel
Copy link

yonoel commented Apr 10, 2022

Thanks for this documentation!
💖🎉

@superloika
Copy link

superloika commented Apr 21, 2022

This works! Thank you!

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