如何通过 HTTP 代理从 Git 存储库中提取内容?

发布于 2024-07-06 05:40:30 字数 1267 浏览 9 评论 0 原文

注意:虽然描述的用例是关于在项目中使用子模块,但这同样适用于通过 HTTP 存储库的正常 git 克隆

我有一个受 Git 控制的项目。 我想添加一个子模块:

git submodule add http://github.com/jscruggs/metric_fu.git vendor/plugins/metric_fu

但是我已经

...
got 1b0313f016d98e556396c91d08127c59722762d0
got 4c42d44a9221209293e5f3eb7e662a1571b09421
got b0d6414e3ca5c2fb4b95b7712c7edbf7d2becac7
error: Unable to find abc07fcf79aebed56497e3894c6c3c06046f913a under http://github.com/jscruggs/metri...
Cannot obtain needed commit abc07fcf79aebed56497e3894c6c3c06046f913a
while processing commit ee576543b3a0820cc966cc10cc41e6ffb3415658.
fatal: Fetch failed.
Clone of 'http://github.com/jscruggs/metric_fu.git' into submodule path 'vendor/plugins/metric_fu'

设置了 HTTP_PROXY:

c:\project> echo %HTTP_PROXY%
http://proxy.mycompany:80

我什至有一个用于 http 代理的全局 Git 设置:

c:\project> git config --get http.proxy
http://proxy.mycompany:80

是否有人通过代理获得 HTTP 获取以一致地工作? 真正奇怪的是 GitHub 上的一些项目运行良好(awesome_nested_set for例如),但其他的始终失败(例如 rails)。

Note: while the use-case described is about using submodules within a project, the same applies to a normal git clone of a repository over HTTP.

I have a project under Git control. I'd like to add a submodule:

git submodule add http://github.com/jscruggs/metric_fu.git vendor/plugins/metric_fu

But I get

...
got 1b0313f016d98e556396c91d08127c59722762d0
got 4c42d44a9221209293e5f3eb7e662a1571b09421
got b0d6414e3ca5c2fb4b95b7712c7edbf7d2becac7
error: Unable to find abc07fcf79aebed56497e3894c6c3c06046f913a under http://github.com/jscruggs/metri...
Cannot obtain needed commit abc07fcf79aebed56497e3894c6c3c06046f913a
while processing commit ee576543b3a0820cc966cc10cc41e6ffb3415658.
fatal: Fetch failed.
Clone of 'http://github.com/jscruggs/metric_fu.git' into submodule path 'vendor/plugins/metric_fu'

I have my HTTP_PROXY set up:

c:\project> echo %HTTP_PROXY%
http://proxy.mycompany:80

I even have a global Git setting for the http proxy:

c:\project> git config --get http.proxy
http://proxy.mycompany:80

Has anybody gotten HTTP fetches to consistently work through a proxy? What's really strange is that a few project on GitHub work fine (awesome_nested_set for example), but others consistently fail (rails for example).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(30

仙气飘飘 2024-07-13 05:41:19
      export HTTP_PROXY="http://USER:[email protected]:8080"

如果用户/密码中有任何特殊字符,请使用

      export HTTP_PROXY="http://USER:[email protected]:8080"

If you have any special characters in the user/password use url_encode.

陪我终i 2024-07-13 05:41:18

最近,如果我使用带有 HTTP 地址的 Git 克隆,

git clone --config "http.proxy=http://<ip>:<port>" https://github.com/<username>/<reponame>.git

GitHub 将需要用户名和密码。
然后它说不再使用这种身份验证方法,因为它不安全。

因此,如果我使用 SSH 方法进行 Git 克隆,一切都会正常。
我注意到 SSH 不会像这样工作:

git clone --config "http.proxy=http://<ip>:<port>" [email protected]:<username>/<reponame>.git

带有代理的 SSH 工作方式如下:

# Edit ~/.ssh/config and paste the text below:
Host github.com
    Hostname ssh.github.com
    Port 443
    ProxyCommand nc -X connect -x <ip>:<port> %h %p

编辑配置文件后,SSH 代理将工作:

git clone [email protected]:<username>/<reponame>.git

提及该配置文件。

我不明白为什么是443端口而不是22端口。
ChatGPT(使用 GPT-4)告诉我,它对我有用。

Recently, if I use Git clone with an HTTP address,

git clone --config "http.proxy=http://<ip>:<port>" https://github.com/<username>/<reponame>.git

GitHub will require a username and password.
And then it says this authentication method is no longer used, because it is not safe.

So, if I use the SSH method to Git clone, things will work.
I noticed that SSH will not work like this:

git clone --config "http.proxy=http://<ip>:<port>" [email protected]:<username>/<reponame>.git

SSH with a proxy works like this:

# Edit ~/.ssh/config and paste the text below:
Host github.com
    Hostname ssh.github.com
    Port 443
    ProxyCommand nc -X connect -x <ip>:<port> %h %p

After editing the config file, the SSH proxy will work:

git clone [email protected]:<username>/<reponame>.git

mention that configuration file.

I don’t understand why it’s 443 port instead of 22.
Just ChatGPT (using GPT-4) told me, and it works for me.

秋风の叶未落 2024-07-13 05:41:17

正如 @user2188765 已经指出的那样,尝试用 http[s]:// 替换存储库的 git:// 协议。 另请参阅此答案

As @user2188765 has already pointed out, try replacing the git:// protocol of the repository with http[s]://. See also this answer.

(り薆情海 2024-07-13 05:41:17

我使用 https 绕过了代理...有些代理甚至不检查 https。

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\git\meantest>git clone http://github.com/linnovate/mean.git
Cloning into 'mean'...
fatal: unable to access 'http://github.com/linnovate/mean.git/': Failed connect
to github.com:80; No error

c:\git\meantest>git clone https://github.com/linnovate/mean.git
Cloning into 'mean'...
remote: Reusing existing pack: 2587, done.
remote: Counting objects: 27, done.
remote: Compressing objects: 100% (24/24), done.
rRemote: Total 2614 (delta 3), reused 4 (delta 0)eceiving objects:  98% (2562/26

Receiving objects: 100% (2614/2614), 1.76 MiB | 305.00 KiB/s, done.
Resolving deltas: 100% (1166/1166), done.
Checking connectivity... done

I got around the proxy using https... some proxies don't even check https.

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

c:\git\meantest>git clone http://github.com/linnovate/mean.git
Cloning into 'mean'...
fatal: unable to access 'http://github.com/linnovate/mean.git/': Failed connect
to github.com:80; No error

c:\git\meantest>git clone https://github.com/linnovate/mean.git
Cloning into 'mean'...
remote: Reusing existing pack: 2587, done.
remote: Counting objects: 27, done.
remote: Compressing objects: 100% (24/24), done.
rRemote: Total 2614 (delta 3), reused 4 (delta 0)eceiving objects:  98% (2562/26

Receiving objects: 100% (2614/2614), 1.76 MiB | 305.00 KiB/s, done.
Resolving deltas: 100% (1166/1166), done.
Checking connectivity... done
我家小可爱 2024-07-13 05:41:16

当我的代理不需要身份验证时,前面的答案对我有用。 如果您使用的代理需要您进行身份验证,那么您可以尝试 CCProxy。 我有关于如何设置它的小教程,

http://blog.praveenkumar.co.in/2012/09/proxy-free-windows-xp78-and-mobiles.html

我能够推送、拉取、创建新的存储库。 一切都很好。 如果您像我一样遇到 Git 问题,请确保彻底卸载并重新安装新版本。

The previous answers worked for me when my proxy didn't need authentication. If you are using proxy which requires you to authenticate then you may try CCProxy. I have small tutorial on how to set it up here,

http://blog.praveenkumar.co.in/2012/09/proxy-free-windows-xp78-and-mobiles.html

I was able to push, pull, create new repositories. Everything worked just fine. Make sure you do a clean uninstall and reinstall of new version if you are facing issues with Git like I did.

寒尘 2024-07-13 05:41:15

$http_proxy 用于 http://github.com....
$https_proxy 用于 https://github.com...

$http_proxy is for http://github.com....
$https_proxy is for https://github.com...

兰花执着 2024-07-13 05:41:15

这不是您的代理的问题。 这是 GitHub(或 Git)的问题。 我在 Linux 上的 Git 1.6.0.1 上也失败了。 错误 已报告(您没有较少的)。

确保删除你的馅饼; 他们已经在 Google 上。 但我想你不能删除它们。 使用 Gist 代替?

This isn't a problem with your proxy. It's a problem with GitHub (or Git). It fails for me on Git 1.6.0.1 on Linux as well. Bug is already reported (by you no less).

Make sure to delete your pasties; they're already on Google. But I guess you can't delete them. Use Gist instead?

旧时模样 2024-07-13 05:41:13

对于 Windows,

请转至 → C:/Users/user_name/gitconfig

使用以下详细信息更新 gitconfig 文件:

[http]

[https]

    proxy = https://your_proxy:your_port

[http]

    proxy = http://your_proxy:your_port

如何检查您的代理和端口号?

互联网资源管理器设置Internet 选项连接LAN 设置

For Windows

Go to → C:/Users/user_name/gitconfig

Update the gitconfig file with the below details:

[http]

[https]

    proxy = https://your_proxy:your_port

[http]

    proxy = http://your_proxy:your_port

How can you check your proxy and port number?

Internet ExplorerSettingsInternet OptionsConnectionsLAN Settings

这个俗人 2024-07-13 05:41:12

您可以使用:

git config --add http.proxy http://user:password@proxy_host:proxy_port

You can use:

git config --add http.proxy http://user:password@proxy_host:proxy_port
停顿的约定 2024-07-13 05:41:12

有一种方法可以为特定 URL 设置代理,请参阅 http..* 部分。 例如,对于 https://github.com/ 可以这样做

git config --global 'http.https://github.com/.proxy' http://proxy.mycompany:80

There is a way to set up a proxy for a specific URL, see the http.<url>.* section in the git config manual. For example, for https://github.com/ one can do

git config --global 'http.https://github.com/.proxy' http://proxy.mycompany:80
红颜悴 2024-07-13 05:41:10

以下方法对我有用:

echo 'export http_proxy=http://username:password@roxy_host:port/' >> ~/.bash_profile
echo 'export https_proxy=http://username:password@roxy_host:port' >> ~/.bash_profile
  • Zsh 注意:修改您的 ~/.zshenv 文件而不是 ~/.bash_profile。
  • Ubuntu 和 Fedora 注意:修改 ~/.bashrc 文件而不是 ~/.bash_profile。

The below method works for me:

echo 'export http_proxy=http://username:password@roxy_host:port/' >> ~/.bash_profile
echo 'export https_proxy=http://username:password@roxy_host:port' >> ~/.bash_profile
  • Zsh note: Modify your ~/.zshenv file instead of ~/.bash_profile.
  • Ubuntu and Fedora note: Modify your ~/.bashrc file instead of ~/.bash_profile.
穿透光 2024-07-13 05:41:09

使用 proxychains

proxychains git pull ...

但 proxychains 已停止使用。 使用 proxychains-ng 代替。

Use proxychains

proxychains git pull ...

But proxychains is discontinued. Use proxychains-ng instead.

听不够的曲调 2024-07-13 05:41:08

值得一提的是:
网上的大多数示例都显示示例

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port

因此,看起来 - 如果您的代理需要身份验证 - 您必须 将您的公司密码留在 git-config 中。 这真的不太酷。

但是,如果您只是配置没有密码的用户:

git config --global http.proxy proxy_user@proxy_ip:proxy_port

Git 似乎(至少在我没有凭据帮助程序的 Windows 机器上)能够识别该用户,并在存储库访问时提示输入代理密码。

Worth to mention:
Most examples on the net show examples like

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port

So it seems, that - if your proxy needs authentication - you must leave your company-password in the git-config. Which isn't really cool.

But, if you just configure the user without password:

git config --global http.proxy proxy_user@proxy_ip:proxy_port

Git seems (at least on my Windows-machine without credentials-helper) to recognize that and prompts for the proxy-password on repo-access.

浊酒尽余欢 2024-07-13 05:41:06

我发现这篇博文通过更新curl证书为我解决了这个问题。

GitHub、CA 错误和旧的curl

This blog post I found solves the problem for me by updating the curl certificates.

GitHub, CA errors and old curl's

胡渣熟男 2024-07-13 05:41:04

我遇到了同样的问题,但修复方法略有不同:使用 HTTP 支持重建 Git

git: 协议无法通过我的公司防火墙。

例如,超时:

git clone git://github.com/miksago/node-websocket-server.git

curl github.com 工作得很好,所以我知道我的 http_proxy 环境变量是正确的。

我尝试使用 http,如下所示,但我立即收到错误。

git clone http://github.com/miksago/node-websocket-server.git

->>>  fatal: Unable to find remote helper for 'http' <<<-

我尝试像这样重新编译 Git:

./configure  --with-curl --with-expat

但仍然遇到致命错误。

最后,经过几个令人沮丧的小时,我阅读了配置文件,并看到了以下内容:

# 如果你的curl头文件和库文件位于

,则定义CURLDIR=/foo/bar

# /foo/bar/include 和 /foo/bar/lib 目录。

我当时想起来,我没有从源代码编译curl,所以就去寻找头文件。 果然,它们没有安装。 这就是问题所在。 Make 并没有抱怨缺少头文件。 所以我没有意识到 --with-curl 选项没有执行任何操作(事实上,它是我的 git 版本中的默认选项)。

我执行了以下操作来修复它:

  1. 添加了 make 所需的标头:

    百胜安装curl-devel
    (expat-devel-1.95.8-8.3.el5_5.3.i386 已安装)。

  2. /usr/local 中删除了 git (因为我希望新安装在那里)。

I simply removed `git*` from `/usr/local/share` and `/usr/local/libexec`
  1. 搜索包含 curlexpat 头文件的包含目录,然后(因为我已通读 configure)将它们添加到环境是这样的:

    导出 CURLDIR=/usr/include
    导出 EXPATDIR=/usr/include

  2. Ran configure 使用以下选项,这些选项再次在 configure 文件本身中进行了描述,并且也是默认值,但是什么哎呀:

    ./configure --with-curl --with-expat

  3. 现在 http 通过我的公司防火墙与 git 一起使用:

    git 克隆 http://github.com/miksago/node-websocket-server .git
    克隆到“node-websocket-server”...

    • 使用默认值时在 .netrc 文件中找不到主机 github.com
    • 即将 connect() 到代理 proxy.entp.attws.com 端口 8080
    • 正在尝试 135.214.40.30... * 已连接
      ...

I had the same problem, with a slightly different fix: rebuilding Git with HTTP support

The git: protocol did not work through my corporate firewall.

For example, this timed out:

git clone git://github.com/miksago/node-websocket-server.git

curl github.com works just fine, though, so I know my http_proxy environment variable is correct.

I tried using http, like below, but I got an immediate error.

git clone http://github.com/miksago/node-websocket-server.git

->>>  fatal: Unable to find remote helper for 'http' <<<-

I tried recompiling Git like so:

./configure  --with-curl --with-expat

But still I got the fatal error.

Finally, after several frustrating hours, I read the configure file, and saw this:

# Define CURLDIR=/foo/bar if your curl header and library files are in

# /foo/bar/include and /foo/bar/lib directories.

I remembered then, that I had not complied curl from source, and so went looking for the header files. Sure enough, they were not installed. That was the problem. Make did not complain about the missing header files. So I did not realize that the --with-curl option did nothing (it is, in fact the default in my version of git).

I did the following to fix it:

  1. Added the headers needed for make:

    yum install curl-devel
    (expat-devel-1.95.8-8.3.el5_5.3.i386 was already installed).

  2. Removed git from /usr/local (as I want the new install to live there).

I simply removed `git*` from `/usr/local/share` and `/usr/local/libexec`
  1. Searched for the include directories containing the curl and expat header files, and then (because I had read through configure) added these to the environment like so:

    export CURLDIR=/usr/include
    export EXPATDIR=/usr/include

  2. Ran configure with the following options, which, again, were described in the configure file itself, and were also the defaults but what the heck:

    ./configure --with-curl --with-expat

  3. And now http works with git through my corporate firewall:

    git clone http://github.com/miksago/node-websocket-server.git
    Cloning into 'node-websocket-server'...

    • Couldn't find host github.com in the .netrc file, using defaults
    • About to connect() to proxy proxy.entp.attws.com port 8080
    • Trying 135.214.40.30... * connected
      ...
一笑百媚生 2024-07-13 05:41:02

这对我有用。

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port

This worked to me.

git config --global http.proxy proxy_user:proxy_passwd@proxy_ip:proxy_port
北方的韩爷 2024-07-13 05:40:59

设置 Git 代理

命令

git config --global http.proxy http://user:password@domain:port

示例

git config --global http.proxy http://clairton:[email protected]:8080

Set up proxy to Git

Command

git config --global http.proxy http://user:password@domain:port

Example

git config --global http.proxy http://clairton:[email protected]:8080
相思碎 2024-07-13 05:40:57

对我来说,这有效:

sudo apt-get install socat

在 $BIN_PATH/gitproxy 中创建一个文件:

#!/bin/sh
_proxy=192.168.192.1
_proxyport=3128
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

不要忘记授予它执行权限:

chmod a+x gitproxy

运行以下命令来设置环境:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy

For me this worked:

sudo apt-get install socat

Create a file inside your $BIN_PATH/gitproxy with:

#!/bin/sh
_proxy=192.168.192.1
_proxyport=3128
exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport

Don’t forget to give it execution permissions:

chmod a+x gitproxy

Run the following commands to set up the environment:

export PATH=$BIN_PATH:$PATH
git config --global core.gitproxy gitproxy
浅浅 2024-07-13 05:40:56

在 Windows 上,如果您不想将密码以纯文本形式放入 .gitconfig 中,可以使用

它会针对普通甚至 Windows NTLM< /a> 代理并启动 localhost-proxy,无需身份验证。

为了让它运行:

  • 安装 Cntml

  • 根据文档配置Cntml以通过代理身份验证

  • 将 Git 指向新的 localhost 代理:

    [http] 
          proxy = http://localhost:3128 # 根据需要更改端口号 
      

On Windows, if you don't want to put your password in .gitconfig in the plain text, you can use

It authenticates you against normal or even Windows NTLM proxy and starts localhost-proxy without authentication.

In order to get it run:

  • Install Cntml

  • Configure Cntml according to documentation to pass your proxy authentication

  • Point Git to your new localhost proxy:

    [http]
        proxy = http://localhost:3128  # Change port number as necessary
    
心的位置 2024-07-13 05:40:55

将 Git credential.helper 设置为 wincred

git config --global credential.helper wincred

确保只有一个 credential.helper

git config -l

如果有多个,并且未设置为 wincred,请将其删除。

git config --system --unset credential.helper

现在设置代理,无需任何密码。

git config --global http.proxy http://<YOUR WIN LOGIN NAME>@proxy:80

检查您添加的所有设置是否看起来都不错...

git config --global -l

现在您就可以开始了!

Set Git credential.helper to wincred.

git config --global credential.helper wincred

Make sure there is only one credential.helper

git config -l

If there is more than one, and it's not set to wincred remove it.

git config --system --unset credential.helper

Now set the proxy without any password.

git config --global http.proxy http://<YOUR WIN LOGIN NAME>@proxy:80

Check that all the settings that you added looks good....

git config --global -l

Now you are good to go!

风向决定发型 2024-07-13 05:40:54

我发现 http.proxyGIT_PROXY_COMMAND 都不适用于经过身份验证的 HTTP 代理。 无论哪种方式都不会触发代理。 但我找到了解决这个问题的方法。

  1. 安装corkscrew,或您想要的其他替代方案。

  2. 创建一个验证文件。 authfile 的格式为:user_name:password,其中 user_namepassword 是您访问您的用户名和密码。代理人。 要创建这样的文件,只需运行如下命令: echo "username:password" > ~/.ssh/authfile.

  3. 编辑~/.ssh/config,并确保其权限为644chmod 644 ~/.ssh/config

以github.com为例如,将以下行添加到 ~/.ssh/config

Host    github.com
        HostName        github.com
        ProxyCommand    /usr/local/bin/corkscrew <your.proxy> <proxy port> %h %p <path/to/authfile>
        User            git

现在,每当您使用 [email protected],它将自动使用代理。 您也可以轻松地对 Bitbucket 执行相同的操作。

这不像其他方法那么优雅,但它很有魅力。

I find neither http.proxy nor GIT_PROXY_COMMAND work for my authenticated HTTP proxy. The proxy is not triggered in either way. But I find a way to work around this.

  1. Install corkscrew, or other alternatives you want.

  2. Create a authfile. The format for authfile is: user_name:password, and user_name, password is your username and password to access your proxy. To create such a file, simply run command like this: echo "username:password" > ~/.ssh/authfile.

  3. Edit ~/.ssh/config, and make sure its permission is 644: chmod 644 ~/.ssh/config

Take github.com as an example, add the following lines to ~/.ssh/config:

Host    github.com
        HostName        github.com
        ProxyCommand    /usr/local/bin/corkscrew <your.proxy> <proxy port> %h %p <path/to/authfile>
        User            git

Now whenever you do anything with [email protected], it will use the proxy automatically. You can easily do the same thing to Bitbucket as well.

This is not so elegant as other approaches, but it works like a charm.

山田美奈子 2024-07-13 05:40:51

如果您使用的是 Windows,并且通过 https URL 进行检索,请考虑设置 HTTPS_PROXY。 这对我有用!

If you are on Windows, consider setting HTTPS_PROXY as well if you are retrieving via an https URL. It worked for me!

隐诗 2024-07-13 05:40:48

您还可以编辑.gitconfig文件位于%userprofile%目录在 Windows 系统上 (notepad %userprofile%.gitconfig) 或在 Linux 系统上的 ~ 目录中 (vi ~/.gitconfig) 以及添加 HTTP 部分,如下所示。

.gitconfig 文件的内容:

[http]
        proxy = http://proxy.mycompany:80

You could also edit the .gitconfig file located in the %userprofile% directory on a Windows system (notepad %userprofile%.gitconfig) or in the ~ directory on a Linux system (vi ~/.gitconfig) and add an HTTP section as below.

Content of the .gitconfig file:

[http]
        proxy = http://proxy.mycompany:80
很酷不放纵 2024-07-13 05:40:46

对我来说, git:// 不能通过代理工作,尽管 https:// 可以。 这引起了一些头痛,因为我运行的脚本都使用 git://,所以我不能轻易地更改它们。 然而我发现了这个GEM

git config --global url."https://github.com/".insteadOf git://github.com/

For me the git:// just doesn't work through the proxy although the https:// does. This caused some bit of headache because I was running scripts that all used git:// so I couldn't just easily change them all. However I found this GEM

git config --global url."https://github.com/".insteadOf git://github.com/
神魇的王 2024-07-13 05:40:44

当您的网络团队通过重写证书进行 SSL 检查时,然后使用 HTTP URL 而不是 HTTPS URL,并结合设置此变量对我有用。

git config --global http.proxy http://proxy:8081

When your network team does SSL inspection by rewriting certificates, then using an HTTP URL instead of an HTTPS one, combined with setting this variable worked for me.

git config --global http.proxy http://proxy:8081
心不设防 2024-07-13 05:40:43

看起来您正在 Windows 上使用 Git 的 MinGW 编译(或者可能是我的另一个版本)没听说过)。 有一些方法可以调试这个:我相信 Git 的所有 HTTP 代理工作都是由 cURL。 在运行 Git 之前设置此环境变量:

GIT_CURL_VERBOSE=1

这至少应该让您了解幕后发生的情况。

It looks like you're using a MinGW compile of Git on Windows (or possibly another one I haven't heard about). There are ways to debug this: I believe all of the HTTP proxy work for Git is done by cURL. Set this environment variable before running Git:

GIT_CURL_VERBOSE=1

This should at least give you an idea of what is going on behind the scenes.

情场扛把子 2024-07-13 05:40:42

如果您只想在指定存储库上使用代理,而不需要在其他存储库上使用代理,则更好的方法是 -c, --config 选项code>git clone 一个存储库。

例如,

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --config "http.proxy=proxyHost:proxyPort"

If you just want to use a proxy on a specified repository, and don't need on other repositories, the preferable way is the -c, --config <key=value> option when you git clone a repository.

E.g.,

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git --config "http.proxy=proxyHost:proxyPort"
生来就爱笑 2024-07-13 05:40:41

最终起作用的是设置 http_proxy 环境变量。 我已经正确设置了 HTTP_PROXY,但 Git 显然更喜欢小写版本。

What finally worked was setting the http_proxy environment variable. I had set HTTP_PROXY correctly, but Git apparently likes the lower-case version better.

时光暖心i 2024-07-13 05:40:39

对此已经有一些很好的答案。 不过,我想我应该参与其中,因为某些代理服务器要求您使用用户 ID 和密码进行身份验证。 有时这可能位于域上。

因此,例如,如果您的代理服务器配置如下:

Server: myproxyserver
Port: 8080
Username: mydomain\myusername
Password: mypassword

然后,使用以下命令添加到您的 .gitconfig 文件:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080

不要担心 https。 只要指定的代理服务器支持 HTTP 和 HTTPS,那么配置文件中的一项就足够了。

然后,您可以通过执行 cat .gitconfig 来验证命令是否已将条目成功添加到您的 .gitconfig 文件中:

在文件末尾,您将看到如下条目:

[http]
       proxy = http://mydomain\\myusername:mypassword@myproxyserver:8080

就是这样!

There are some great answers on this already. However, I thought I would chip in as some proxy servers require you to authenticate with a user Id and password. Sometimes this can be on a domain.

So, for example if your proxy server configuration is as follows:

Server: myproxyserver
Port: 8080
Username: mydomain\myusername
Password: mypassword

Then, add to your .gitconfig file, using the following command:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080

Don't worry about https. As long as the specified proxy server supports HTTP, and HTTPS, then one entry in the configuration file will suffice.

You can then verify that the command added the entry to your .gitconfig file successfully by doing cat .gitconfig:

At the end of the file, you will see an entry as follows:

[http]
       proxy = http://mydomain\\myusername:mypassword@myproxyserver:8080

That's it!

佼人 2024-07-13 05:40:35

您还可以在全局配置属性 http.proxy 中设置 Git 使用的 HTTP 代理:

git config --global http.proxy http://proxy.mycompany:80

使用代理进行身份验证:(

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080/

信用转到 @EugeneKulabuhov@JaimeReynoso 用于身份验证格式。)

You can also set the HTTP proxy that Git uses in global configuration property http.proxy:

git config --global http.proxy http://proxy.mycompany:80

To authenticate with the proxy:

git config --global http.proxy http://mydomain\\myusername:mypassword@myproxyserver:8080/

(Credit goes to @EugeneKulabuhov and @JaimeReynoso for the authentication format.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文