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

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

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


当前回答

下面是代理设置

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

其他回答

使用命令:

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

将proxyuser更改为代理用户 将proxypwd更改为您的代理密码 将proxy.server.com更改为代理服务器的URL 将8080更改为代理服务器上配置的代理端口

注意,这适用于http和https回购。

如果你决定在任何时候重置这个代理并在没有代理的情况下工作:

使用命令:

git config --global --unset http.proxy

最后,检查当前设置的代理:

git config --global --get http.proxy

尝试将以下内容放到~/。gitconfig文件:

[http]
    proxy = http://proxy:8080
[https]
    proxy = http://proxy:8080
[url "https://"]
    insteadOf = git://

在终端上设置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

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

#!/bin/sh

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

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

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