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

后端 未结 28 2766
星月不相逢
星月不相逢 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: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   %h %p 
            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.

提交回复
热议问题