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

@chenrq2005
Copy link

Thanks! Great job! It worked for me.

@atulkumarpccs
Copy link

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

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

@duangsuse
Copy link

Thank you <3

@kvnloughead
Copy link

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

@MaratZakirov
Copy link

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

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

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

does anyone know how i can get this?

@leensabbouh
Copy link

thank u

@HosseinMohammadii
Copy link

thanks bro

@taozuhong
Copy link

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

@refayathaque
Copy link

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

@xundeenergie
Copy link

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

Thanks a lot

@nagarajasr
Copy link

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

Thanks for this documentation!
💖🎉

@yonoel
Copy link

yonoel commented Apr 10, 2022

Thanks for this documentation!
💖🎉

@superloika
Copy link

This works! Thank you!

@victorovento
Copy link

Thanks!

@klauswoolhouse
Copy link

klauswoolhouse commented Aug 31, 2022

Thank you for sharing the code. It's quite useful. I am engaged in marketing research. Now, I use residential rotating proxies because proxy servers based on data centers no longer cope with the necessary tasks, and more reliable proxies are needed. Now the traffic passes through the provider and disguises itself under a different name, which is very convenient. Still, I had a problem using a proxy in some applications, and your code is very useful for my work in this case.

@MwauStephen
Copy link

Thank you for this detailed documentation

@YunaH2324
Copy link

I'm wanting to make a personal proxy, but I've never coded anything on any site before. I'm really confused on how to use this site, and where to put coding things. Long story short, I'm really confused and need help :')

@Makhsum
Copy link

Makhsum commented Dec 22, 2022

Спасибо

@YaroslavKharchenko0
Copy link

This worked for me:

git config --global http.proxy ""

Thanks

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