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

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

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


当前回答

这对我来说是可行的,在公司防火墙后面的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的名称

其他回答

这对我来说是可行的,在公司防火墙后面的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的名称

因为在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 Bash ssh-keygen.exe -t rsa -C 打开你的Git提供商(Github, Bitbucket等) 添加复制id_rsa。pub文件内容到Git提供者的输入页面(检查您的配置文件)

对于git协议(git://…),安装socat并编写如下脚本:

#!/bin/sh

exec socat - socks4:your.company.com:$1:$2

使其可执行,将其放在您的路径和~/中。Gitconfig set core。Gitproxy到该脚本的名称。

在终端上设置git代理

if

您不希望为每个git项目逐个手动设置代理 始终希望对所有项目使用相同的代理

全局设置一次

git config --global http.proxy username:password@proxy_url:proxy_port
git config --global https.proxy username:password@proxy_url:proxy_port

如果您只想为一个git项目设置代理 (在某些情况下,对于某些git连接,你可能不想使用相同的代理或任何代理)

//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

如果要显示当前代理设置

git config --list 

如果要全局删除代理

git config --global --unset http.proxy
git config --global --unset https.proxy

如果您只想删除一个git根的代理

//go to project root
cd /bla-bla/project_root
git config --unset http.proxy
git config --unset https.proxy