Getting Git to work with a proxy server - fails with “Request timed out”

前端 未结 19 2460
旧时难觅i
旧时难觅i 2020-11-22 05:09

How do I get Git to use a proxy server?

I need to check out code from a Git server, but it shows \"Request timed out\" every time. How do I get around this?

相关标签:
19条回答
  • 2020-11-22 05:21

    Command to use:

    git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
    
    • change proxyuser to your proxy user
    • change proxypwd to your proxy password
    • change proxy.server.com to the URL of your proxy server
    • change 8080 to the proxy port configured on your proxy server

    Note that this works for both http and https repos.

    If you decide at any time to reset this proxy and work without proxy:

    Command to use:

    git config --global --unset http.proxy
    

    Finally, to check the currently set proxy:

    git config --global --get http.proxy
    
    0 讨论(0)
  • 2020-11-22 05:24

    Try to put the following to the ~/.gitconfig file:

    [http]
        proxy = http://proxy:8080
    [https]
        proxy = http://proxy:8080
    [url "https://"]
        insteadOf = git://
    
    0 讨论(0)
  • 2020-11-22 05:25

    If you are using ubuntu, then do the following ...

    Step 1 : Install corkscrew

    $ sudo apt-get install corkscrew
    

    Step 2 : Write a script named git-proxy.sh and add the following

    #!/bin/sh
    
    exec corkscrew <name of proxy server> <port> $*
    
    # <name_of_proxy_server> and <port> are the ip address and port of the server
    # e.g. exec corkscrew 192.168.0.1 808 $*
    

    Step 3 : Make the script executable

    $ chmod +x git-proxy.sh
    

    Step 4 : Set up the proxy command for GIT by setting the environment variable

    $ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"
    

    Now use the git commands,such as

    git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
    
    0 讨论(0)
  • 2020-11-22 05:25

    Setting git proxy on terminal

    if

    • you do not want set proxy for each of your git projects manually, one by one
    • always want to use same proxy for all your projects

    Set it globally once

    git config --global http.proxy username:password@proxy_url:proxy_port
    git config --global https.proxy username:password@proxy_url:proxy_port
    

    if you want to set proxy for only one git project (there may be some situations where you may not want to use same proxy or any proxy at all for some git connections)

    //go to project root
    cd /bla_bla/project_root
    //set proxy for both http and https
    git config http.proxy username:password@proxy_url:proxy_port
    git config https.proxy username:password@proxy_url:proxy_port
    

    if you want to display current proxy settings

    git config --list 
    

    if you want to remove proxy globally

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

    if you want to remove proxy for only one git root

    //go to project root
    cd /bla-bla/project_root
    git config --unset http.proxy
    git config --unset https.proxy
    
    0 讨论(0)
  • 2020-11-22 05:27

    Faced same issue because of multiple .gitconfig files in windows, followed below steps to fix the same:

    Step 1: Open Git BASH

    Step 2: Look for .gitconfig, executing following command:

    git config --list --global --show-origin
    

    Step 3: Copy the below content in .gitconfig:

    [http]
        proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
        sslverify = false
    [https]
        proxy = http://YOUR_PROXY_USERNAME:YOUR_PROXY_PASSWORD@YOUR.PROXY.SERVER:YOUR.PROXY.SERVER.PORT
        sslverify = false
    [url "http://github.com/"]
        insteadOf = git://github.com/
    
    [user]
        name = Arpit Aggarwal
        email = aggarwalarpit.89@gmail.com
    
    0 讨论(0)
  • 2020-11-22 05:29

    As an alternative to using git config --global http.proxy address:port, you can set the proxy on the command line:

    git -c "http.proxy=address:port" clone https://...
    

    The advantage is the proxy is not persistently set. Under Bash you might set an alias:

    alias git-proxy='git -c "http.proxy=address:port"'
    
    0 讨论(0)
提交回复
热议问题