如何通过 HTTP 代理从 Git 存储库中提取内容?
注意:虽然描述的用例是关于在项目中使用子模块,但这同样适用于通过 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)。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
如果用户/密码中有任何特殊字符,请使用
If you have any special characters in the user/password use url_encode.
最近,如果我使用带有 HTTP 地址的 Git 克隆,
GitHub 将需要用户名和密码。
然后它说不再使用这种身份验证方法,因为它不安全。
因此,如果我使用 SSH 方法进行 Git 克隆,一切都会正常。
我注意到 SSH 不会像这样工作:
带有代理的 SSH 工作方式如下:
编辑配置文件后,SSH 代理将工作:
提及该配置文件。
我不明白为什么是443端口而不是22端口。
ChatGPT(使用 GPT-4)告诉我,它对我有用。
Recently, if I use Git clone with an HTTP address,
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:
SSH with a proxy works like this:
After editing the config file, the SSH proxy will work:
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.
正如 @user2188765 已经指出的那样,尝试用
http[s]://
替换存储库的git://
协议。 另请参阅此答案。As @user2188765 has already pointed out, try replacing the
git://
protocol of the repository withhttp[s]://
. See also this answer.我使用 https 绕过了代理...有些代理甚至不检查 https。
I got around the proxy using https... some proxies don't even check https.
当我的代理不需要身份验证时,前面的答案对我有用。 如果您使用的代理需要您进行身份验证,那么您可以尝试 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.
$http_proxy 用于 http://github.com....
$https_proxy 用于 https://github.com...
$http_proxy is for http://github.com....
$https_proxy is for https://github.com...
这不是您的代理的问题。 这是 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?
对于 Windows,
请转至 → C:/Users/user_name/gitconfig
使用以下详细信息更新 gitconfig 文件:
如何检查您的代理和端口号?
互联网资源管理器 → 设置 → Internet 选项 → 连接 → LAN 设置
For Windows
Go to → C:/Users/user_name/gitconfig
Update the gitconfig file with the below details:
How can you check your proxy and port number?
Internet Explorer → Settings → Internet Options → Connections → LAN Settings
您可以使用:
You can use:
有一种方法可以为特定 URL 设置代理,请参阅 http..* 部分 。 例如,对于
https://github.com/
可以这样做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, forhttps://github.com/
one can do以下方法对我有用:
The below method works for me:
使用 proxychains
但 proxychains 已停止使用。 使用 proxychains-ng 代替。
Use proxychains
But proxychains is discontinued. Use proxychains-ng instead.
值得一提的是:
网上的大多数示例都显示示例
因此,看起来 - 如果您的代理需要身份验证 - 您必须 将您的公司密码留在 git-config 中。 这真的不太酷。
但是,如果您只是配置没有密码的用户:
Git 似乎(至少在我没有凭据帮助程序的 Windows 机器上)能够识别该用户,并在存储库访问时提示输入代理密码。
Worth to mention:
Most examples on the net show examples like
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 seems (at least on my Windows-machine without credentials-helper) to recognize that and prompts for the proxy-password on repo-access.
我发现这篇博文通过更新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
我遇到了同样的问题,但修复方法略有不同:使用 HTTP 支持重建 Git
git:
协议无法通过我的公司防火墙。例如,超时:
curl github.com
工作得很好,所以我知道我的http_proxy
环境变量是正确的。我尝试使用
http
,如下所示,但我立即收到错误。我尝试像这样重新编译 Git:
但仍然遇到致命错误。
最后,经过几个令人沮丧的小时,我阅读了配置文件,并看到了以下内容:
我当时想起来,我没有从源代码编译
curl
,所以就去寻找头文件。 果然,它们没有安装。 这就是问题所在。 Make 并没有抱怨缺少头文件。 所以我没有意识到--with-curl
选项没有执行任何操作(事实上,它是我的git
版本中的默认选项)。我执行了以下操作来修复它:
添加了 make 所需的标头:
百胜安装curl-devel
(expat-devel-1.95.8-8.3.el5_5.3.i386 已安装)。
从
/usr/local
中删除了git
(因为我希望新安装在那里)。搜索包含
curl
和expat
头文件的包含目录,然后(因为我已通读configure
)将它们添加到环境是这样的:导出 CURLDIR=/usr/include
导出 EXPATDIR=/usr/include
Ran
configure
使用以下选项,这些选项再次在configure
文件本身中进行了描述,并且也是默认值,但是什么哎呀:./configure --with-curl --with-expat
现在
http
通过我的公司防火墙与git
一起使用:git 克隆 http://github.com/miksago/node-websocket-server .git
克隆到“node-websocket-server”...
...
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:
curl github.com
works just fine, though, so I know myhttp_proxy
environment variable is correct.I tried using
http
, like below, but I got an immediate error.I tried recompiling Git like so:
But still I got the fatal error.
Finally, after several frustrating hours, I read the configure file, and saw this:
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 ofgit
).I did the following to fix it:
Added the headers needed for make:
yum install curl-devel
(expat-devel-1.95.8-8.3.el5_5.3.i386 was already installed).
Removed
git
from/usr/local
(as I want the new install to live there).Searched for the include directories containing the
curl
andexpat
header files, and then (because I had read throughconfigure
) added these to the environment like so:export CURLDIR=/usr/include
export EXPATDIR=/usr/include
Ran
configure
with the following options, which, again, were described in theconfigure
file itself, and were also the defaults but what the heck:./configure --with-curl --with-expat
And now
http
works withgit
through my corporate firewall:git clone http://github.com/miksago/node-websocket-server.git
Cloning into 'node-websocket-server'...
...
这对我有用。
This worked to me.
设置 Git 代理
命令
示例
Set up proxy to Git
Command
Example
对我来说,这有效:
在 $BIN_PATH/gitproxy 中创建一个文件:
不要忘记授予它执行权限:
运行以下命令来设置环境:
For me this worked:
Create a file inside your $BIN_PATH/gitproxy with:
Don’t forget to give it execution permissions:
Run the following commands to set up the environment:
在 Windows 上,如果您不想将密码以纯文本形式放入 .gitconfig 中,可以使用
它会针对普通甚至 Windows NTLM< /a> 代理并启动 localhost-proxy,无需身份验证。
为了让它运行:
安装 Cntml
根据文档配置Cntml以通过代理身份验证
将 Git 指向新的 localhost 代理:
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:
将 Git credential.helper 设置为 wincred。
确保只有一个 credential.helper
如果有多个,并且未设置为 wincred,请将其删除。
现在设置代理,无需任何密码。
检查您添加的所有设置是否看起来都不错...
现在您就可以开始了!
Set Git credential.helper to wincred.
Make sure there is only one credential.helper
If there is more than one, and it's not set to wincred remove it.
Now set the proxy without any password.
Check that all the settings that you added looks good....
Now you are good to go!
我发现
http.proxy
和GIT_PROXY_COMMAND
都不适用于经过身份验证的 HTTP 代理。 无论哪种方式都不会触发代理。 但我找到了解决这个问题的方法。安装corkscrew,或您想要的其他替代方案。
创建一个验证文件。
authfile
的格式为:user_name:password
,其中user_name
、password
是您访问您的用户名和密码。代理人。 要创建这样的文件,只需运行如下命令:echo "username:password" > ~/.ssh/authfile
.编辑
~/.ssh/config
,并确保其权限为644
:chmod 644 ~/.ssh/config
以github.com为例如,将以下行添加到
~/.ssh/config
:现在,每当您使用
[email protected]
,它将自动使用代理。 您也可以轻松地对 Bitbucket 执行相同的操作。这不像其他方法那么优雅,但它很有魅力。
I find neither
http.proxy
norGIT_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.Install corkscrew, or other alternatives you want.
Create a authfile. The format for
authfile
is:user_name:password
, anduser_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
.Edit
~/.ssh/config
, and make sure its permission is644
:chmod 644 ~/.ssh/config
Take github.com as an example, add the following lines to
~/.ssh/config
: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.
如果您使用的是 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!
您还可以编辑.gitconfig文件位于
%userprofile%
目录在 Windows 系统上 (notepad %userprofile%.gitconfig) 或在 Linux 系统上的~
目录中 (vi ~/.gitconfig) 以及添加 HTTP 部分,如下所示。.gitconfig 文件的内容:
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:
对我来说, git:// 不能通过代理工作,尽管 https:// 可以。 这引起了一些头痛,因为我运行的脚本都使用 git://,所以我不能轻易地更改它们。 然而我发现了这个GEM
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
当您的网络团队通过重写证书进行 SSL 检查时,然后使用 HTTP URL 而不是 HTTPS URL,并结合设置此变量对我有用。
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.
看起来您正在 Windows 上使用 Git 的 MinGW 编译(或者可能是我的另一个版本)没听说过)。 有一些方法可以调试这个:我相信 Git 的所有 HTTP 代理工作都是由 cURL。 在运行 Git 之前设置此环境变量:
这至少应该让您了解幕后发生的情况。
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:
This should at least give you an idea of what is going on behind the scenes.
如果您只想在指定存储库上使用代理,而不需要在其他存储库上使用代理,则更好的方法是
-c, --config
选项code>git clone 一个存储库。例如,
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 yougit clone
a repository.E.g.,
最终起作用的是设置
http_proxy
环境变量。 我已经正确设置了HTTP_PROXY
,但 Git 显然更喜欢小写版本。What finally worked was setting the
http_proxy
environment variable. I had setHTTP_PROXY
correctly, but Git apparently likes the lower-case version better.对此已经有一些很好的答案。 不过,我想我应该参与其中,因为某些代理服务器要求您使用用户 ID 和密码进行身份验证。 有时这可能位于域上。
因此,例如,如果您的代理服务器配置如下:
然后,使用以下命令添加到您的
.gitconfig
文件:不要担心
https
。 只要指定的代理服务器支持 HTTP 和 HTTPS,那么配置文件中的一项就足够了。然后,您可以通过执行
cat .gitconfig
来验证命令是否已将条目成功添加到您的.gitconfig
文件中:在文件末尾,您将看到如下条目:
就是这样!
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:
Then, add to your
.gitconfig
file, using the following command: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 doingcat .gitconfig
:At the end of the file, you will see an entry as follows:
That's it!
您还可以在全局配置属性
http.proxy
中设置 Git 使用的 HTTP 代理:使用代理进行身份验证:(
信用转到 @EugeneKulabuhov 和 @JaimeReynoso 用于身份验证格式。)
You can also set the HTTP proxy that Git uses in global configuration property
http.proxy
:To authenticate with the proxy:
(Credit goes to @EugeneKulabuhov and @JaimeReynoso for the authentication format.)