Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Working with git behind proxy

I'm behind a proxy. To get git working I would have to add

proxy = http://username:[email protected]:8080

to .gitconfig.

Since username and password are my system credentials this solution sucks because I would have to store these as cleartext.

I'm using Google Chrome where I don't need to setup any proxy settings because it uses the system proxy settings.

How to do that with git?

like image 833
Razer Avatar asked Mar 09 '13 11:03

Razer


1 Answers

Update February 2016:

With git 2.8 (March 2016), you don't have to embed in clear text your password in the url.

See commit 372370f, commit ef97639 (26 Jan 2016) by Knut Franke (``).
Helped-by: Junio C Hamano (gitster), Eric Sunshine (sunshinebell28), and Elia Pinto (devzero2000).
(Merged by Junio C Hamano -- gitster -- in commit 30f302f, 03 Feb 2016)

http: use credential API to handle proxy authentication

Currently, the only way to pass proxy credentials to curl is by including them in the proxy URL. Usually, this means they will end up on disk unencrypted, one way or another (by inclusion in ~/.gitconfig, shell profile or history).
Since proxy authentication often uses a domain user, credentials can be security sensitive; therefore, a safer way of passing credentials is desirable.

If the configured proxy contains a username but not a password, query the credential API for one. Also, make sure we approve/reject proxy credentials properly. So:

In addition to the syntax understood by curl, it is possible to specify a proxy string with a user name but no password, in which case git will attempt to acquire one in the same way it does for other credentials.
See gitcredentials for more information.
The syntax thus is:

[protocol://][user[:password]@]proxyhost[:port]

This can be overridden on a per-remote basis; see remote.<name>.proxy.


Update Oct. 2015

Since git 1.8.0 and commit 7bcb747, the default Windows credential helper is wincred, a git credential helper that interface with Windows' Credential Manager.

 git config --global credential.helper wincred

Original answer (March 2013):

You can use a credential helper (git1.7.9+) like git-credential-winstore on Windows, in order to store your credentials.
You will declare it with a 'git config --global credential.helper winstore'.
You can then declare your proxy without putting your username and password:

git config --global http.proxy http://proxy.server.com:8080

(although I prefer using environment variables http_proxy and https_proxy)

See also "git: 'credential-cache' is not a git command"


like image 168
VonC Avatar answered Oct 12 '22 22:10

VonC