How do I pull from a Git repository through an HTTP proxy?

后端 未结 28 2238
星月不相逢
星月不相逢 2020-11-22 11:57

Note: while the use-case described is about using submodules within a project, the same applies to a normal git clone of a repository over HTTP.

I have

相关标签:
28条回答
  • 2020-11-22 12:11

    The below method works for me:

    echo 'export http_proxy=http://username:password@roxy_host:port/' >> ~/.bash_profile
    echo 'export https_proxy=http://username:password@roxy_host:port' >> ~/.bash_profile
    
    • Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.
    • Ubuntu and Fedora note: Modify your ~/.bashrc file instead of ~/.bash_profile.
    0 讨论(0)
  • 2020-11-22 12:13

    For me what it worked was:

    sudo apt-get install socat
    

    Create a file inside your $BIN_PATH/gitproxy with:

    #!/bin/sh 
    _proxy=192.168.192.1 
    _proxyport=3128 
    exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
    

    Dont forget to give it execution permissions

    chmod a+x gitproxy
    

    Run following commands to setup environment:

    export PATH=$BIN_PATH:$PATH
    git config --global core.gitproxy gitproxy
    
    0 讨论(0)
  • 2020-11-22 12:13

    Use proxychains

    proxychains git pull ...
    

    update: proxychains is discontinued, use proxychains-ng instead.

    0 讨论(0)
  • 2020-11-22 12:14

    This is an old question but if you are on Windows, consider setting HTTPS_PROXY as well if you are retrieving via an https URL. Worked for me!

    0 讨论(0)
  • 2020-11-22 12:14

    I find neither http.proxy nor GIT_PROXY_COMMAND work for my authenticated http proxy. The proxy is not triggered in either way. But I find a way to work around this.

    1. Install corkscrew, or other alternatives you want.
    2. Create a authfile. The format for authfile is: user_name:password, and user_name, password is your username and password to access your proxy. To create such a file, simply run command like this: echo "username:password" > ~/.ssh/authfile.

    3. Edit ~/.ssh/config, and make sure its permission is 644: chmod 644 ~/.ssh/config

    Take github.com as an example, add the following lines to ~/.ssh/config:

    Host    github.com
            HostName        github.com
            ProxyCommand    /usr/local/bin/corkscrew <your.proxy> <proxy port> %h %p <path/to/authfile>
            User            git
    

    Now whenever you do anything with git@github.com, it will use the proxy automatically. You can easily do the same thing to Bitbucket as well.

    This is not so elegant as other approaches, but it works like a charm.

    0 讨论(0)
  • 2020-11-22 12:14

    as @user2188765 has already pointed out, try replacing the git:// protocol of the repository with http[s]://. See also this answer

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