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 10:05

I have tried all the above answers and nothing worked for me, as there was a proxy password encoding issues.

This command worked:

git config --global http-proxy http://username@proxy.example.com:PortNumber 

Do not enter the password in your command. It will dynamically ask for when you try to connect to any git repo.

查看更多
君临天下
3楼-- · 2018-12-31 10:07

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

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
查看更多
泛滥B
4楼-- · 2018-12-31 10:09

If you have tsocks or proxychains installed and configured, you can

$ tsocks git clone <you_repository>

or

$ proxychains git clone <you_repository>

to make it shorter, I created a symbol link /usr/bin/p for proxychains, so I can use it like this

p git clone <you_repository>

and I can use it to proxy any command,

p <cmd-need-be-proxied>

by the way, proxychains is not updated for a long time, you may wanna try proxychians-ng

查看更多
琉璃瓶的回忆
5楼-- · 2018-12-31 10:10

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
查看更多
骚的不知所云
6楼-- · 2018-12-31 10:12

For windows users: if git config or set http_proxy= doesn't work, this answer may help:

replace the git:// protocol of the git repository with http://. Note, you'll have to set the http_proxy first, anyways.

查看更多
荒废的爱情
7楼-- · 2018-12-31 10:13

If the command line way of configuring your proxy server doesn't work, you can probably just edit .gitconfig (in the root of your profile, which may hide both in C:\Documents and Settings and on some network drive) and add this:

[http]
    proxy = http://username:password@proxy.at.your.org:8080

YMMV though, this only covers the first step of the command line configuration. You may have to edit the system git configuration too and I have no idea where they hid that.

查看更多
登录 后发表回答