如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
如何让Git使用代理服务器?
我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?
或者如何设置代理服务器?
当前回答
如果您已经安装和配置了tsocks或proxychains,则可以
$ tsocks git clone <you_repository>
or
$ proxychains git clone <you_repository>
为了使它更短,我为proxychains创建了一个符号link /usr/bin/p,所以我可以像这样使用它
p git clone <you_repository>
我可以用它来代理任何命令
p <cmd-need-be-proxied>
顺便说一下,proxychains很长一段时间没有更新,你可能想试试proxychians-ng
其他回答
在不知疲倦地尝试这个页面上的每个解决方案后,我的工作是使用SSH密钥代替!
打开Git Bash ssh-keygen.exe -t rsa -C 打开你的Git提供商(Github, Bitbucket等) 添加复制id_rsa。pub文件内容到Git提供者的输入页面(检查您的配置文件)
如果你正在使用ubuntu,那么执行以下操作…
步骤1:安装开瓶器
$ sudo apt-get install corkscrew
步骤2:编写名为git-proxy.sh的脚本,并添加以下内容
#!/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 $*
步骤3:使脚本可执行
$ chmod +x git-proxy.sh
步骤4:通过设置环境变量为GIT设置代理命令
$ export GIT_PROXY_COMMAND="/<path>/git-proxy.sh"
现在使用git命令,例如
git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
下面是代理设置
git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>
使用代理的另一种选择是使用SSH 在git配置中,在ssh地址上配置origin remote。然后使用ssh-keygen命令,它会给你一个公钥,你可以在你的GitLab或Gitab帐户设置和登录相应完成…
1-通过在git客户端中运行git remote -v来验证哪些遥控器正在使用。
2-如果这是http(s) url,将其更改为ssh地址,执行:git remote set-url <远程名称,例如origin> <新的ssh url > 例如
git remote set-url git@gitlab.com:example/myproject.git
3 .如果需要生成登录的SSH密钥,执行命令SSH -keygen -o,该命令生成public(id_rsa. key)。Pub文件)和私钥。
4份公钥内容。(从id_rsa。酒吧文件)
5-去gitlab/githup/....配置文件>设置/ssh-key。创建新的SSH密钥并粘贴公钥内容
设置一个名为http_proxy的系统变量,其值为“ProxyServer:Port”。 这是最简单的解决办法。分别使用daefu在评论中指出的https_proxy。
设置gitproxy(正如sleske提到的)是另一个选项,但这需要一个“命令”,它不像上面的解决方案那么简单。
引用: http://bardofschool.blogspot.com/2008/11/use-git-behind-proxy.html