Using Git on Windows, behind an HTTP proxy, without storing proxy password on disk

前端 未结 4 949
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 00:05

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 p

相关标签:
4条回答
  • 2020-12-13 00:28

    If you are behind Proxy server, follow this.

    Make sure port 9418 is excluded from your firewall rules.Ask network administrator

    Unset Proxy if it is already set:

    • git config --global --unset http.proxy
    • git config --global --unset https.proxy

    Set the proper Proxy:

    • git config --global http.proxy http://username:password@proxydomain:port
    • git config --global https.proxy http://username:password@proxydomain:port

    Common Errors:

    • 502: URL/IP is unreachable from your network.
    • 407: Proxy authentication Denied.
    • 80 : Proxy has not been set properly.
    0 讨论(0)
  • 2020-12-13 00:35

    since git 2.8.0

    git config --global http.proxy http://[user]@proxyhost:port
    git config --global credential.helper wincred
    
    0 讨论(0)
  • 2020-12-13 00:35

    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
    
    0 讨论(0)
  • 2020-12-13 00:37

    Instead of using git setting, you can also use environment variable (that you can set just for your session), as described in this answer:

    set http_proxy=http://username:password@proxydomain:port
    set https_proxy=http://username:password@proxydomain:port
    set no_proxy=localhost,.my.company 
    

    So your wrapper script could, instead of modifying the .gitconfig (and leaving your password in plain text) set environment variables on demand, just for your current session.

    As noted by Welgriv, this is unsafe since environmental variables can be accessed by any program in user mode.


    These days (2020, 5+ years later), I prefer:

    set http_proxy=http://127.0.0.1:3128
    set https_proxy=http://127.0.0.1:3128
    

    With 127.0.0.1:3128 being the default URL for a genotrance/px, a small HTTP proxy server, which will automatically authenticate through an NTLM proxy.
    No password or even user to set.

    0 讨论(0)
提交回复
热议问题