Getting git to work with a proxy server

2018-12-31 09:45发布

How do I get git to use a proxy server?

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

Alternatively, how can I set a proxy server?

18条回答
其实,你不懂
2楼-- · 2018-12-31 09:48

Set a system variable named http_proxy with the value of ProxyServer:Port. That is the simplest solution. Respectively, use https_proxy as daefu pointed out in the comments.

Setting gitproxy (as sleske mentions) is another option, but that requires a "command", which is not as straightforward as the above solution.

References: http://bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html

查看更多
只若初见
3楼-- · 2018-12-31 09:48

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"'
查看更多
人间绝色
4楼-- · 2018-12-31 09:49

here is the proxy setting

git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>
查看更多
姐姐魅力值爆表
5楼-- · 2018-12-31 09:49

After tirelessly trying every solution on this page, my work around was to use and SSH key instead!

  1. Open Git Bash
  2. $ ssh-keygen.exe -t rsa -C
  3. Open your Git provider (Github, Bitbucket, etc.)
  4. Add copy the id_rsa.pub file contents into Git provider's input page (check your profile)
查看更多
荒废的爱情
6楼-- · 2018-12-31 09:52

I work on Windows XP at work(state/gov), so I did my research and found this here and it worked for me. Hope this helps :)

The http_proxy Environment Variable

If you use a proxy server or firewall, you may need to set the http_proxy environment variable in order to access some url from commandline. Example : Installing ppm for perl or applying rpm in linux ,updating ubuntu

Set the http_proxy variable with the hostname or IP address of the proxy server: http_proxy=http:// [proxy.example.org]

If the proxy server requires a user name and password, include them in the following form: http_proxy=http:// [username:password@proxy.example.org]

If the proxy server uses a port other than 80, include the port number: http_proxy=http:// [username:password@proxy.example.org:8080]

Windows XP

  1. Open the Control Panel and click the System icon.
  2. On the Advanced tab, click on Environment Variables.
  3. Click New in the System variables panel.
  4. Add http_proxy with the appropriate proxy information (see examples above).

Linux, Solaris or HP-UX

Set the http_proxy environment variable using the command specific to your shell (e.g. set or export). To make this change persistent, add the command to the appropriate profile file for the shell. For example, in bash, add a line like the following to your .bash_profile or .bashrc file:

  1. http_proxy=http:// [username:password@hostname:port];
  2. export $http_proxy
查看更多
有味是清欢
7楼-- · 2018-12-31 09:53

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

[http]
    proxy = http://proxy:8080
[https]
    proxy = http://proxy:8080
[url "https://"]
    insteadOf = git://
查看更多
登录 后发表回答