无法使用 http/https 将 Git 推送到远程存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5264949/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot push Git to remote repository with http/https
提问by Clément
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.
我在服务器上由 apache 服务的目录中有一个 Git 存储库。我已经配置了 WebDAV,它似乎运行正常。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
错误:无法访问 URL https://git.example.com/repo/,返回代码 22 致命:git-http-push failed
Any idea?
任何的想法?
采纳答案by Arrowmaster
It is highly suggested NOT to use WebDAV if possible. If you must use HTTP/HTTPS then usage of the git-http-backendCGI script is recommended over WebDAV.
如果可能,强烈建议不要使用 WebDAV。如果您必须使用 HTTP/HTTPS,那么推荐使用git-http-backendCGI 脚本而不是 WebDAV。
回答by Deepak
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:[email protected]/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 的配置文件中的身份验证详细信息,然后推送到所需的分支。
回答by VonC
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. In myhttpd-dav.conf
, I have the line…
查看之后
/Web/git/Logs/ErrorLog
,我发现锁定文件存在权限问题。在我的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 Arrowmasterin his (upvoted) answer, the smart http protocolis now part of recent Git distribution.
The git-http-backend
CGI script can takes care of any git commands through http.
正如 Eddie 在评论中和Arrowmaster在他的(赞成)回答中提到的那样,智能 http 协议现在是最近 Git 发行版的一部分。
该git-http-backend
CGI脚本可以通过HTTP照顾任何Git命令的。
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
).
(Merged by Junio C Hamano -- gitster
--in commit 39a1dd8, 13 Feb 2018)
请参阅Patryk Obara ( )提交的 a2b9820(2018 年 1 月 24 日)。(由Junio C Hamano合并-- --在commit 39a1dd8,2018 年 2 月 13 日)dreamer
gitster
http-push
: improve error logWhen
git push
fails due to server-side WebDAV error, it's not easy to point to the main culprit.
Additional information about exactcURL
error and HTTP server response is helpful for debugging purpose.
http-push
: 改进错误日志当
git push
由于服务器端 WebDAV 错误而失败时,很难指出罪魁祸首。
有关确切cURL
错误和 HTTP 服务器响应的附加信息有助于调试目的。
回答by JrBriones
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 存储库中做出贡献的每个成员都这样做。
回答by gaspar
回答by Robert Murphy
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.comto 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).
我在 Windows 上遇到了同样的问题,我的凭据存储在 Windows 凭据管理器中。我不希望每个用户都必须编辑配置文件,所以我将 url 从http://example.com更改 为http://[email protected],即使我的 ID 不是 git,它也能工作。我认为没有在任何地方定义用户“git”并假设任何名称都可以使用。(如果您不在专用网络上,请确保使用 https)。
回答by FearlessFuture
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.
我有一个类似的问题,我可以使用 HTTP 协议从存储库中克隆和拉取,但我无法推送。我通过执行以下操作解决了这个问题。
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.
我在项目的 .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 设置。
回答by Rapha?l Gertz
En example of write authentified git dav virtualhost with gitweb enable that could solve your problem :
使用 gitweb enable 编写认证的 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>
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.
将密码放在克隆 url 中是一种不良的安全做法,因为任何人都可以在您的 .git/config 中读取它。