无法使用 http/https 将 Git 推送到远程存储库

发布于 2024-10-21 11:22:32 字数 300 浏览 2 评论 0 原文

我在服务器上的 apache 提供的目录中有一个 Git 存储库。我已经配置了 WebDAV 并且它似乎运行正常。 Litmus 返回 100% 成功。

我可以从远程主机克隆我的存储库,但是当尝试推送 http 或 https 时,出现以下错误:

错误:无法访问 URL https://git.example.com/repo/,返回代码 22 致命:git-http-推送失败

有什么想法吗?

I have a Git repository in a directory served by apache on a server. I have configured WebDAV and it seems to be running correctly. Litmus returns 100% success.

I can clone my repository from a remote host, but when trying to push over http or https, I get the following error:

error: Cannot access URL
https://git.example.com/repo/, return code 22 fatal: git-http-push failed

Any idea?

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

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

发布评论

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

评论(7

残月升风 2024-10-28 11:22:32

编辑 .git/config 文件的以下部分:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://git.repository.url/repo.git

然后

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://username:[email protected]/repo.git

尝试 git Push origin master

根据需要编辑其他存储库 URL 的配置文件中的身份验证详细信息,然后推送到所需的分支。

Edit the following section of your .git/config file:

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://git.repository.url/repo.git

to

[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = http://username:[email protected]/repo.git

Then try git push origin master.

Edit the authentication details in your config files for other repository URLs as required and push to the required branch.

∞琼窗梦回ˉ 2024-10-28 11:22:32

强烈建议尽可能不要使用 WebDAV。如果必须使用 HTTP/HTTPS,则使用 建议使用 git-http-backend CGI 脚本而不是 WebDAV。

It is highly suggested NOT to use WebDAV if possible. If you must use HTTP/HTTPS then usage of the git-http-backend CGI script is recommended over WebDAV.

娇纵 2024-10-28 11:22:32

就像这个发表评论,您的 /Web/git/Logs/ErrorLog 对于该错误有何评论?

查看/Web/git/Logs/ErrorLog后,我发现锁定文件存在权限问题。
在我的 httpd-dav.conf 中,我有一行…

DavLockDB “/usr/var/DavLock”

然后我检查了 /usr/ 目录,'var' 目录丢失了。

$ mkdir var
$ cd var
$ chown www .
$ chgrp www .

然后重复这个过程似乎现在我可以推动了! =)


正如埃迪在评论中和 Arrowmaster 在他的(已投票)答案智能 http 协议 现在是最新 Git 发行版的一部分。
git-http-backend< /code> CGI 脚本可以通过 http 处理任何 git 命令。

智能http

更智能的协议(git 和 ssh)将与服务器上的 git upload-pack 进程进行对话,该进程将确定客户端所需的确切对象集,并仅使用这些对象构建自定义包文件并将其流式传输.


Git 2.17(2018 年第 2 季度)将添加调试辅助功能。

请参阅 提交 a2b9820(2018 年 1 月 24 日),作者:Patryk Obara(梦想家
(由 Junio C Hamano -- gitster -- 合并于 提交 39a1dd8,2018 年 2 月 13 日)

http-push:改进错误日志

git push 由于服务器端 WebDAV 错误而失败时,不容易
指出罪魁祸首。
有关确切 cURL 错误和 HTTP 服务器响应的其他信息有助于调试目的。

As in this post comment, what does your /Web/git/Logs/ErrorLog says about that error?

After looking in /Web/git/Logs/ErrorLog, I found out there’s a permission problem on the lock file.
In my httpd-dav.conf, I have the line…

DavLockDB “/usr/var/DavLock”

I then checked the /usr/ directory, the ‘var’ directory was missing.

$ mkdir var
$ cd var
$ chown www .
$ chgrp www .

And then repeating the process seems that now I can push!! =)


As mentioned by Eddie in the comments and by Arrowmaster in his (upvoted) answer, the smart http protocol is now part of recent Git distribution.
The git-http-backend CGI script can takes care of any git commands through http.

smart http

The smarter protocols (git and ssh) would instead have a conversation with the git upload-pack process on the server which would determine the exact set of objects the client needs and build a custom packfile with just those objects and stream it over.


Git 2.17 (Q2 2018) will add a debugging aid.

See commit a2b9820 (24 Jan 2018) by Patryk Obara (dreamer).
(Merged by Junio C Hamano -- gitster -- in commit 39a1dd8, 13 Feb 2018)

http-push: improve error log

When git push fails due to server-side WebDAV error, it's not easy to
point to the main culprit.
Additional information about exact cURL error and HTTP server response is helpful for debugging purpose.

流星番茄 2024-10-28 11:22:32

您可能需要将用户添加为存储库的成员,并可能需要更新权限。

我们必须与每个将在我们组织的 github 存储库上做出贡献的成员一起这样做。

you might need to add the user as a member for the repository and possibly update permissions.

we had to do this with each member that will be contributing on our organizations github repository.

夏了南城 2024-10-28 11:22:32

我在 Windows 上遇到了同样的问题,我的凭据存储在 Windows 凭据管理器中。我不希望每个用户都必须编辑配置文件,因此我更改了 http://example.com 的网址到 http://[电子邮件受保护] 即使我的 id 不是 git,它也能工作。我不认为用户“git”在任何地方定义,并假设任何名称都可以工作。 (如果您不在专用网络上,请确保使用 https)。

I had the same issue on Windows where my credentials are stored in windows credential manager. I did not want every user to have to edit the config file so I changed the url from http://example.com to http://[email protected] and it work even though my id is not git. I don't think a user "git" is defined anywhere and assume any name will work. (If you are not on a private network make sure you use https).

长不大的小祸害 2024-10-28 11:22:32

我遇到了类似的问题,我能够使用 HTTP 协议从存储库中克隆和拉取,但无法推送。我通过执行以下操作解决了这个问题。

我更改了项目 .git/config 文件中远程的 url 以匹配 GitHub SSH url。然后,我按照“https://help.github”中的所有说明进行操作。 com/articles/generate-ssh-keys#platform-linux”并使用“https://help.github.com/articles/error-permission-denied-publickey"。最好的部分是我没有处理 Apache 或更改远程服务器上的任何 HTTP 设置。

I had a similar issue in which I was able to clone and pull from the repository using the HTTP protocol, but I was not able to push. I solved this by doing the following.

I changed the url for the remote in the project's .git/config file to match the GitHub SSH url. I then followed all of the instructions at "https://help.github.com/articles/generating-ssh-keys#platform-linux" and troubleshooted with "https://help.github.com/articles/error-permission-denied-publickey". The best part is that I did not have deal with Apache or change any HTTP settings on the remote server.

一百个冬季 2024-10-28 11:22:32

使用 gitweb 启用写入经过验证的 git dav 虚拟主机的示例可以解决您的问题:

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName git.example.com

        DocumentRoot /var/git

        # SSL configuration
        SSLEngine on

        # Fix dav header
        #RequestHeader edit Destination ^https: http: early

        <Directory /var/git>
                DAV on
                Options ExecCgi FollowSymLinks

                # Gitweb config
                AddHandler cgi-script .cgi
                DirectoryIndex .gitweb.cgi
                SetEnv GITWEB_CONFIG /var/git/.gitweb.conf

                # Basic auth config
                AuthType Basic

                # Auth title
                AuthName "Git repositories"

                # Use file and external providers
                AuthBasicProvider file

                # File location
                AuthUserFile /var/git/.htpasswd

                Require method GET OPTIONS PROPFIND
                <LimitExcept GET OPTIONS PROPFIND>
                        Require valid-user
                </LimitExcept>
        </Directory>
</VirtualHost>

然后只需使用您的用户克隆您的存储库:

git clone https://[email protected]/repository

当您尝试推送时,它会询问您的密码并提供密码。

将密码放在克隆 URL 中是一种不好的安全做法,因为任何人都可以在 .git/config 中读取它。

En example of write authentified git dav virtualhost with gitweb enable that could solve your problem :

<VirtualHost *:443>
        ServerAdmin [email protected]
        ServerName git.example.com

        DocumentRoot /var/git

        # SSL configuration
        SSLEngine on

        # Fix dav header
        #RequestHeader edit Destination ^https: http: early

        <Directory /var/git>
                DAV on
                Options ExecCgi FollowSymLinks

                # Gitweb config
                AddHandler cgi-script .cgi
                DirectoryIndex .gitweb.cgi
                SetEnv GITWEB_CONFIG /var/git/.gitweb.conf

                # Basic auth config
                AuthType Basic

                # Auth title
                AuthName "Git repositories"

                # Use file and external providers
                AuthBasicProvider file

                # File location
                AuthUserFile /var/git/.htpasswd

                Require method GET OPTIONS PROPFIND
                <LimitExcept GET OPTIONS PROPFIND>
                        Require valid-user
                </LimitExcept>
        </Directory>
</VirtualHost>

Then just clone your repository with your user :

git clone https://[email protected]/repository

And when you will try to push it will ask your password and provide it.

Placing the password in the clone url is a security bad practice as anyone can read it in your .git/config.

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