简体   繁体   English

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

[英]Cannot push Git to remote repository with http/https

I have a Git repository in a directory served by apache on a server. 我在服务器上由apache提供服务的目录中有一个Git存储库。 I have configured WebDAV and it seems to be running correctly. 我已经配置了WebDAV,它似乎正在运行。 Litmus returns 100% success. Litmus返回100%的成功。

I can clone my repository from a remote host, but when trying to push over http or https, I get the following error: 我可以从远程主机克隆我的存储库,但在尝试推送http或https时,我收到以下错误:

error: Cannot access URL https://git.example.com/repo/ , return code 22 fatal: git-http-push failed 错误:无法访问网址https://git.example.com/repo/ ,返回代码22致命:git-http-push failed

Any idea? 任何想法?

Edit the following section of your .git/config file: 编辑.git / config文件的以下部分:

[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:password@git.repository.url/repo.git

Then try git push origin master . 然后尝试git push origin master

Edit the authentication details in your config files for other repository URLs as required and push to the required branch. 根据需要在配置文件中编辑其他存储库URL的身份验证详细信息,然后推送到所需的分支。

It is highly suggested NOT to use WebDAV if possible. 强烈建议尽可能不使用WebDAV。 If you must use HTTP/HTTPS then usage of the git-http-backend CGI script is recommended over WebDAV. 如果必须使用HTTP / HTTPS,则建议通过WebDAV使用git-http-backend CGI脚本。

As in this post comment , what does your /Web/git/Logs/ErrorLog says about that error? 在这篇帖子评论中 ,您的/Web/git/Logs/ErrorLog对该错误的描述是什么?

After looking in /Web/git/Logs/ErrorLog , I found out there's a permission problem on the lock file. 在查看/Web/git/Logs/ErrorLog ,我发现锁定文件存在权限问题。 In my httpd-dav.conf , I have the line… 在我的httpd-dav.conf ,我有一行......

DavLockDB “/usr/var/DavLock”

I then checked the /usr/ directory, the ' var ' directory was missing. 然后我检查了/usr/目录,缺少' var '目录。

$ 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. 正如Eddie在评论中提到的那样,以及Arrowmaster在他的(upvoted) 答案中提到的, 智能http协议现在是最近Git发行版的一部分。
The git-http-backend CGI script can takes care of any git commands through http. git-http-backend CGI脚本可以通过http处理任何git命令。

聪明的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和ssh)将与服务器上的git upload-pack进程进行对话,这将确定客户端所需的确切对象集,并仅使用这些对象构建自定义包文件并将其流式传输。


Git 2.17 (Q2 2018) will add a debugging aid. Git 2.17(2018年第二季度)将添加一个调试辅助工具。

See commit a2b9820 (24 Jan 2018) by Patryk Obara ( dreamer ) . Patryk Obara( dreamer 提交a2b9820 (2018年1月24日
(Merged by Junio C Hamano -- gitster -- in commit 39a1dd8 , 13 Feb 2018) (由Junio C gitster合并- gitster -提交39a1dd8 ,2018年2月13日)

http-push : improve error log http-push :改进错误日志

When git push fails due to server-side WebDAV error, it's not easy to point to the main culprit. git push因服务器端WebDAV错误而失败时,指向主要罪魁祸首并不容易。
Additional information about exact cURL error and HTTP server response is helpful for debugging purpose. 有关确切cURL错误和HTTP服务器响应的其他信息有助于调试目的。

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. 我们必须与将在我们的组织github存储库上做出贡献的每个成员执行此操作。

I've got the same problem, and found the solutions, maybe it will be useful for someone. 我遇到了同样的问题,并找到了解决方案,也许对某人有用。
Here is my solution with git-http-backend configuration and ldap authentication. 是我的git-http-backend配置和ldap身份验证的解决方案。

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. 我有一个类似的问题,我可以使用HTTP协议克隆和从存储库中提取,但我无法推送。 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. 我在项目的.git / config文件中更改了远程的url以匹配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 ". 然后我按照“ https://help.github.com/articles/generating-ssh-keys#platform-linux ”中的所有说明进行操作,并使用“ 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. 最好的部分是我没有处理Apache或更改远程服务器上的任何HTTP设置。

I had the same issue on Windows where my credentials are stored in windows credential manager. 我在Windows上遇到了同样的问题,我的凭据存储在Windows凭证管理器中。 I did not want every user to have to edit the config file so I changed the url from http://example.com to http://git@example.com and it work even though my id is not git. 我不希望每个用户都必须编辑配置文件,因此我将URL从http://example.com更改为http://git@example.com ,即使我的id不是git,它也能正常工作。 I don't think a user "git" is defined anywhere and assume any name will work. 我不认为用户“git”在任何地方定义并假设任何名称都可以。 (If you are not on a private network make sure you use https). (如果您不在专用网络上,请确保使用https)。

En example of write authentified git dav virtualhost with gitweb enable that could solve your problem : 使用gitweb enable编写authentified git dav虚拟主机的示例可以解决您的问题:

<VirtualHost *:443>
        ServerAdmin admin@example.com
        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://user@git.example.com/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. 将密码放在克隆URL中是一种安全性不好的做法,因为任何人都可以在.git / config中读取它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM