24

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?

7 Answers 7

40

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Yes just adding the username:password worked for me, and everything else failed.
My config already had a username. I added a password and now all is good. I've no intention of moving from WebDAV for my tiny project with a repo on a Synology NAS... so this tip was a life saver!
Thanks! Used this for multiple GitHub accounts on the same local dev machine. No silly SSH multi-identity-config.
That worked, you don't need to add username & password anymore
11

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.

1 Comment

You are absolutely right, I read an old manual in which there was no mention of git-http-backend. So I gave up with WebDAV and configured this. It's easier, cleaner, and it works!
3

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.

2 Comments

I did not find the ErrorLog, but I can say the lock was there and the permissions were good.
As ArrowMaster pointed out, it is best to move away from DAV which is slower and more prone to update conflicts. Instead use git-http-backend.cgi, and the appropriate apache ScriptAlias deinitions.
2

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.

Comments

1

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).

1 Comment

please give example.
0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.