ChatGPT解决这个技术问题 Extra ChatGPT

GitHub Windows client behind proxy

I'm trying to get the GitHub client for Windows working. I am on a corporate Win 7 x64 computer behind a corporate proxy and firewall. Following various other posts and experimenting with multiple combinations of environment variables and config variables I have found the only way to get cloning and push updates to work is by using the HTTPS_PROXY environment variable, including my full corporate domain user ID and password.

This is unacceptable from a security standpoint. Is there any other way to get this to work?

Additional notes:

The following worked:

Add an environment variable called HTTPS_PROXY with the value http://[domain]\[userid]:[password]@someproxy.mycorp.com:8080

The following did not work:

Omitting user id and password from HTTPS_PROXY variable

Using an environment variable called HTTP_PROXY (no S)

Adding the http.proxy variable to the global config file (.gitconfig)

Adding the https.proxy variable to the global config file

In all cases, the GitHub client still does not recognize the proxy: The content of the file TheLog.txt always shows the following on startup:

[time]|INFO|thread:4|GitHub.Helpers.StartupLogger|Proxy information: (None)
[time]|INFO|thread:4|GitHub.Helpers.StartupLogger|Couldn't fetch creds for proxy

And is followed by the output of several failed proxy authentication attempts, all of which indicate "Credentials are missing."

Adding the environment variable did the trick for me, but it is an unacceptable solution, as it exposes my domain/password to any application with access to the environment variables.
jacobbenson.com/?p=302#sthash.DzPYdGUU.dpbs explains that this is caused by the gui (which correctly uses the windows set proxy) calls msysgit behind the scenes for the git commands. msysgit uses libcurl for http requests, which doesn't use the windows proxy settings. There is work ongoing to fix this in several areas including with libgit2sharp at github.com/libgit2/libgit2sharp.

h
hexYeah

Add these entries to your '.gitconfig' file in your user directory (go to %USERPROFILE%):

[http]
    proxy = http://<proxy address>:<proxy port>

[https]
    proxy = https://<proxy address>:<proxy port>

And if you don't want to store your password in plaintext, I would use a local proxy forwarder like CNTLM which allows you to direct all traffic through it and can store the passwords hashed.

Unlike the original question, if you don't care if your password is in plain text add these:

[http]
    proxy = http://<username>:<password>@<proxy address>:<proxy port>

[https]
    proxy = https://<username>:<password>@<proxy address>:<proxy port>

see edufinn answer if you need authorization against the proxy: proxy=http://:@:
@JanHommes The original question was specifically asking about how to do it without storing the password in plaintext
@Sogger If my password include "@" character, how should i configure the password, thanks for your help.
If you are using CNTLM, make sure you point the proxy to 127.0.0.1 instead of localhost, as suggested. In Windows, it appears that localhost points first to the IPv6 address, which CNTLM doesn't listen to. As such, git will wait until the timeout (several minutes) before switching to the IPv4 address.
A
Anton

Tried everything of above - and didn't succeed, only thing that helped me is CNTLM - http://cntlm.sourceforge.net/.

Install it and run cntlm -H, than authenticate to corp proxy, edit cntlm.ini file with the output of cntlm, restart the windows service. Update .gitconfig with:

[https] proxy = localhost:3128
[http] proxy = localhost:3128

Now cntlm will do all the authentication, and you'll be able to use GitHub(and Dropbox, btw) behind the corp proxy. At least until next password change :) (than do cntlm -H stuff again)


If remote actions like git clone, fetch or pull take a very long time to complete, try switching the .gitconfig to: [https] proxy = 127.0.0.1:3128 [http] proxy = 127.0.0.1:3128
restart what windows service?
@Mukus cntlm - it runs in service mode after installation, if I remember correctly.
I made the change, restarted it and it still does not work.
e
edufinn

I was able to make GitHub Shell to work with our corporate proxy. I'm starting GitHub Shell and execute following command:

export http_proxy=http://<username>:<password>@<corporate proxy>:3128

I would really like to make GUI to work too. But I don't want to set Windows global environment variable which contains my corporate credential information.

Strangely GitHub GUI Client is able to connect to GitHub for user authentication, but only problem is with cloning, pulling and pushing projects from and into GitHub. It seems like the problem is with git implementation. I was able to configure git to run through our proxy without putting my credentials in the git global settings and it was asking for my credentials while performing pull or push requests. But that was working only in Git Shell.


That's because probably GitHub authenticates internally with some component that pulls proxy info from the OS, possibly some SingleSignOn solution, while git itself does not. I have the same problem with SourceTree. I also found that when git works, it takes an impossibly long time to work, making SourceTree usage impossible.
This is likely because Github is trying to use the git port which is typically filtered as its not a common one for IT folks to see. See my answer for an alternative.
M
Manivannan

If you’re using GitHub for Windows in a corporate, chances are high that you’re behind a big bad Corporate Firewall/Proxy. GitHub for Windows doesn’t yet have the proxy parameters in its GUI for setting Options.

To configure GitHub for Windows to use your corporate proxy, edit the .gitconfig file typically found at C:\Users\.gitconfig or C:\Documents & Settings\.gitconfig

Close GitHub for Windows; In .gitconfig, just add

[https] proxy = proxy.yourcompany.com:port


D
DustinTheDev

I've also run into this issue, and tried to dig into it a bit as well (disassembled the client).

The piece of code that generates the log messages we're seeing is as follows:

private static void LogProxyServerConfiguration()
{
    WebProxy defaultProxy = WebProxy.GetDefaultProxy();
    string str = defaultProxy.Address != (Uri)null ? defaultProxy.Address.ToString() : "(None)";
    StartupLogger.log.Info((IFormatProvider)CultureInfo.InvariantCulture, "Proxy information: {0}", str);
    try
    {
        if (defaultProxy.Credentials == null)
        {
            StartupLogger.log.Info((IFormatProvider)CultureInfo.InvariantCulture, "Couldn't fetch creds for proxy", new object[0]);
        }
        else
        {
            NetworkCredential credential = defaultProxy.Credentials.GetCredential(GitHubClient.GitHubDotComUri, "Basic");
            StartupLogger.log.Info((IFormatProvider)CultureInfo.InvariantCulture, "Proxy is authenticated: {0}", credential != null && !string.IsNullOrWhiteSpace(credential.UserName));
        }
    }
    catch (Exception ex)
    {
        StartupLogger.log.InfoException("Couldn't fetch creds for proxy", ex);
    }
}

So this block only logs the proxy information that's setup in IE. The log message appears to have no bearing on what we have setup in the config files or environmental variables.


b
bysreg

i dont know about your firewall, but my campus use proxy

do you use any git gui? EDIT : just noticed that you're using github client for windows

i am using tortoisegit and its very easy to set the proxy. Just right click anywhere, tortoisegit>network, enable proxy server and set server address, username, and password. done

as far as i remember, tortoisegit will also works out-of-the-box with github.


r
royatirek

Here is the way to set proxy in github

git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>

Here in my college we don't have username and password, so if our college ip is 172.16.10.10 and port is 8080

git config --global http.proxy http://172.16.10.10:8080
git config --global https.proxy http://172.16.10.10:8080

P.S -> I would recommend using this method to set proxy as things will fall into place as you will learn further
Source


A
Aksakal almost surely binary

I found this blog to be useful. It describes ntlmaps proxy. It's probably less secure, but worked smoothly. I couldn't get cntlm working.


A
AdamsTips

For us, the solution involved two different things. First, as described in Sogger's answer, you need to add the entries to your .gitconfig file, located in %USERPROFILE%.

[http]
    proxy = http://<proxy address>:<proxy port>

[https]
    proxy = https://<proxy address>:<proxy port>

Second, (and this was the missing piece for us,) you need to configure an exception on the proxy server to allow non-authenticated proxy traffic to *.github.com

https://i.stack.imgur.com/5KVzb.jpg

The problem is not so much the proxy, but the authentication. Bypassing the authentication requirement allows the needed communication to clone and work with projects using the GitHub desktop client.

Also note that this approach did not require storing proxy credentials in the .gitconfig file.


D
David Ferenczy Rogožan

In case you need to force Git or GitHub client to bypass the proxy (use the direct connection), just set the proxy URI in the .gitconfig to an empty string. You'll probably have to edit the file manually, I didn't manage to persuade the git config command to set the value of a configuration directive to an empty string (tried git config --global http.proxy "").

So just add the following lines to the ~/.gitconfig:

[http]
    proxy = ""
[https]
    proxy = "" 

This will not work if you are in a corporate environment and there is no way to bypass the proxy.