如何让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
其他回答
这对我来说是可行的,在公司防火墙后面的windows XP系统中。
我不需要安装任何本地代理或任何其他软件,除了git v1.771从http://code.google.com/p/msysgit/downloads/list?can=3
$ git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080
$ git config --system http.sslcainfo /bin/curl-ca-bundle.crt
$ git remote add origin https://mygithubuser:mygithubpwd@github.com/repoUser/repoName.git
$ git push origin master
proxyuser=我们IT部门分配给我的代理用户,在我的情况下,它是我用来登录我的PC的同一个windows用户,Active Directory用户
Proxypwd =我的代理用户密码
proxy.server.com:8080 =代理名称和端口,我从控制面板,互联网选项,连接,局域网设置按钮,代理服务器部分内的高级按钮,使用第一行(http)上的服务器名和端口。
mygithubuser =我用来登录github.com的用户
Mygithubpwd =我的github.com用户密码
repoUser = repo的用户所有者
repoName = repo的名称
在不知疲倦地尝试这个页面上的每个解决方案后,我的工作是使用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
除了这些答案,我发现考虑以下两点很有帮助:
可能需要强制一个身份验证方案:
[http]
# https://github.com/git/git/blob/master/Documentation/config.txt
proxyAuthMethod = anyauth|basic|digest|negotiate|ntlm
此外,通常使用NTLM身份验证模式时,可能需要显式地提供AD域。
在git bash中:
echo %userdomain%
并更新http。相应的代理:
git config --global http.proxy http://DOMAIN\\proxyuser:proxypwd@proxy.server.com:8080
无论如何,添加CURL日志可能有助于调查:
export GIT_CURL_VERBOSE=1
我已经尝试了以上所有的答案,但都不适合我,因为有一个代理密码编码问题。
这个命令起作用了:
git config --global http.proxy http://username@proxy.example.com:PortNumber
请不要在命令中输入密码。当你尝试连接到任何git repo时,它会动态地询问。