Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@atmosmps
Forked from evantoli/GitConfigHttpProxy.md
Last active December 23, 2020 00:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atmosmps/55adfe01e6f0f862112772fc39b73279 to your computer and use it in GitHub Desktop.
Save atmosmps/55adfe01e6f0f862112772fc39b73279 to your computer and use it in GitHub Desktop.
Configure Git to use a proxy - English and Portuguese Version

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

Configurando o git para usar com proxy

De forma resumida

Você pode precisar configurar seu servidor de proxy se estiver tendo problemas para clonar ou buscar de um repositório remoto ou se estiver recebendo um erro como unable to access '...' Couldn't resolve host '...'.

Considere fazer algo como:

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

Ou para um domínio específico, algo como:

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

Configurar o http. <Url> .sslVerify para false pode ajudar rapidamente você a continuar se o seu local de trabalho utilizar o proxy do intermediário HTTPS do tipo an-in-the-middle. A longo prazo, você pode obter o CA raiz/principal que eles estão aplicando à cadeia de certificados e especificá-los com http.sslCAInfo ou http.sslCAPath.

Veja também a documentação [git-config] (https://git-scm.com/docs/git-config), especialmente as seguintes, se você estiver com problemas de HTTPS / SSL.

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

Em Detalhes

Configurando o Proxy

Você pode configurar globalmente em seu arquivo de usuario ~ / .gitconfig usando a opção --global, ou localmente em um repositório no seu arquivo .git / config.

Configurando o Proxy Globalmente

Configure o proxy de forma global se todos os acessos a todos os repositórios exigirem um proxy. BS: você também pode usar esta configuração se vocês estiver sob um domínio de proxy em uma instituição por exemplo.

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

Proxy específico para uma URL

Se você deseja especificar que um proxy deve ser usado por apenas algumas URLs que especificam o URL como uma subseção de configuração do git usando a notação http. <url> .key:

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

O que resultará no seguinte no arquivo ~ / .gitconfig:

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

Lidando com erros subseqüentes do protocolo SSL

Se você ainda está tendo problemas para clonar ou buscar e agora está recebendo uma mensagem unable to access 'https://...': Unknown SSL protocol error in connection to ...:443 então você pode decidir desativar a verificação de SSL para uma única operação usando a opção -c http.sslVerify=false.

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

Uma vez clonado, você pode decidir definir isso apenas para o repositório local clonado em .git / config. Observe a ausência do --global:

git config http.sslVerify false

Se você optar por torná-lo global, limite-o a um URL usando a notação http. <url> .sslVerify:

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

O que resultará no seguinte no arquivo ~ / .gitconfig:

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

Mostrando a configuração atual

Para mostrar a configuração atual para todas as seções http

git config --get-regexp http.*

Se você estiver em uma pasta de um repositório clonado localmente, use o --global e veja todas as configurações atuais:

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

Limpando/Desativando as configurações de proxy ou verificação de SSL

Utilize a tag --unset para remover uma configuração específica sobre uma propriedade -- por exemplo, se era http.proxy ou http. <url> .proxy. Considere o uso de qualquer uma das seguintes formas:

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

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