如何让Git使用代理服务器?

我需要从Git服务器签出代码,但它每次都显示“请求超时”。我该怎么解决这个问题呢?

或者如何设置代理服务器?


当前回答

下面是代理设置

git config --global http.proxy http://<username>:<pass>@<ip>:<port>
git config --global https.proxy http://<username>:<pass>@<ip>:<port>

其他回答

因为在windows中有多个.gitconfig文件而面临同样的问题,遵循以下步骤来修复相同的问题:

步骤1:打开Git BASH

步骤2:查找.gitconfig,执行以下命令:

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

步骤3:在.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

使用代理的另一种选择是使用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密钥并粘贴公钥内容

我遵循了这里推荐的大部分答案。首先,我得到了以下错误:

致命:无法访问 https://github.com/folder/sample.git/':频道:下一个 InitializeSecurityContext失败:未知错误(0x80092012) 属性的撤销功能无法检查 证书。

然后我尝试了@Salim Hamidi的以下命令

git config --global http.proxy http://proxyuser:proxypwd@proxy.server.com:8080

但我得到了以下错误:

致命:无法访问 'https://github.com/folder/sample.git/':接收到的HTTP代码 407从代理连接后

如果代理服务器无法验证SSL证书,就会发生这种情况。所以我们想要确保ssl验证是关闭的(不推荐用于不受信任的站点),所以我已经完成了以下步骤,这是@Arpit推荐的,但略有变化:

1.首先确保删除之前的所有代理设置:

git config --global --unset http.proxy

2.然后列出并获取gitconfig内容

git config --list --show-origin

3.最后更新gitconfig文件的内容如下:

[http]
sslCAInfo = C:/yourfolder/AppData/Local/Programs/Git/mingw64/ssl/certs/ca-bundle.crt
sslBackend = schannel
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false
[https]
proxy = http://proxyuser:proxypwd@proxy.server.com:8080
sslverify = false

我已经尝试了以上所有的答案,但都不适合我,因为有一个代理密码编码问题。

这个命令起作用了:

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

请不要在命令中输入密码。当你尝试连接到任何git repo时,它会动态地询问。

如果你正在使用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