'Using Git on Windows, behind an HTTP proxy, without storing proxy password on disk
I'm using Git on Windows, on a corporate network where I'm behind an HTTP proxy with Basic authentication. Outbound SSH doesn't work, so I have to use HTTPS through the proxy.
I'm aware of how to use git config http.proxy to configure the settings as http://[username]:[password]@[proxy]:[port].
However, particularly as this is a shared machine, I'd rather not store my password in my .gitconfig. Additionally, changing my .gitconfig using the git config command leaves my password in my bash history, so even if I remember to clear my .gitconfig at the end of the session, I'll almost certainly forget to clear my history as well.
I've tried setting http.proxy without a password, in the vain hope that I'd get a prompt asking me for my password when I try to push/pull, but I only get a 407 Proxy Authentication Required. All the information I've found online seems to either ignore the issues with having the password saved in plaintext in .gitconfig, or deals with NTLM proxies.
I'm quite happy to type my proxy details every time I need to connect - the best solution I can see at the moment is writing a wrapper script that will prompt for my password and set that as an environment variable when calling git proper. Is this a decent solution, and are there any security implications to setting an environment variable for a single call in a script? Preferably, are there any built-in settings or existing tools that I can use for this?
Solution 1:[1]
since git 2.8.0
git config --global http.proxy http://[user]@proxyhost:port
git config --global credential.helper wincred
Solution 2:[2]
VonC's answer doesn't always solve the problem. I don't know why, but it may depend on the proxy server - or maybe it's some other issue alltogether?
It may help to replace the git:// protocol of the repository with http://.
Note: As in VonC's answer, you'll have to setup the http(s)_proxy environment variables first:
set http_proxy=http://username:password@proxydomain:port
set https_proxy=http://username:password@proxydomain:port
For example, clone marble's stable git would usually be cloned like this (from the marble documentation):
git clone -b Applications/15.12 git://anongit.kde.org/marble ~/marble/sources
In windows' cmd (assuming http_proxy has been set), you may then have to use http[s]:// instead:
git clone -b Applications/15.12 http://anongit.kde.org/marble ~/marble/sources
Solution 3:[3]
I know this is an old post but thought I should add a note. In Windows 10, I did the above command in git bash as "git config --global https.proxy http://[userid]:[passwordWithSpclChars]@url:port" ... but since my credential has special characters, I had to then edit the config file C:\USERS<userid>.gitconfig to URL encode the special characters in my credential. Then I was able to proceed with git fetch from origin.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | iowatiger08 |
