git push fatal failed

24

3

I somehow deleted the whole directory of my code branch. I cloned a new one. It worked fine except pushing.

~/workspace/wtf (mybranch)]$ git push origin  mybranch 
error: Cannot access URL [my url], return code 22
fatal: git-http-push failed 

git pull works, though. How can I fix it?

user398384

Posted 2010-10-16T03:16:51.520

Reputation:

1

Please, read this manual here and notice the point about http.receivepack.

– hhh – 2012-06-12T03:00:38.523

Answers

33

I made the mistake of using https instead of ssh for a fresh copy. I since then made modifications and commits but could not push for obvious reasons.

To recover, I simple changed the section [remote "origin"] in .git/config from

url = https://github.com/AIFDR/riab_core.git

to

url = git@github.com:AIFDR/riab_core.git

After that, I could push again.

Ole

Posted 2010-10-16T03:16:51.520

Reputation:

2No need to move to another protocol, read my answer below if you would like to push over http. – Basil A – 2011-05-15T12:58:06.767

1Agree with Basil, this is unnecessary, and impossible in some corporate environments that have limited access through firewalls, etc. – None – 2011-08-24T15:22:48.880

...the problem is with git-http-push failed, I see the op is trying to set up things either over http or https, -1. – hhh – 2012-06-12T15:54:31.020

14

Faster HTTP Push with only git - webDAV is not required

The new "smart-http" support since git 1.6.6. The new method allows the entire pack to be transmitted at once, and not as individual files.

YOu can also use gitweb to provide browable URLs at the same location.

Note: Because access is controlled by apache you can add any Auth requirements (htaccess or ldap, etc) to the setup for each repository.

This answer assumes you own the remote server and want to add/fix http support.

FIRST: Check the apache logs, its likely a permission denied/unable to locate error when apache tries to execute the git-http-backed cgi scripts.

Adding HTTP Support to git

Just make a new git_support.conf file, and include it in apache (add include statement in httpd.conf)

#
#  Basic setup for git-http-backend
#

SetEnv GIT_PROJECT_ROOT /opt/git_repos
SetEnv GIT_HTTP_EXPORT_ALL
SetEnv REMOTE_USER=$REDIRECT_REMOTE_USER  #IMportant !!! This could be your problem if missing

<Directory /opt/git>  # both http_backend and gitweb should be somewhere under here
        AllowOverride None
        Options +ExecCGI -Includes  #Important! Lets apache execute the script!
        Order allow,deny
        Allow from all
</Directory>

# This pattern matches git operations and passes them to http-backend
ScriptAliasMatch \
        "(?x)^/git/(.*/(HEAD | \
                        info/refs | \
                        objects/(info/[^/]+ | \
                                 [0-9a-f]{2}/[0-9a-f]{38} | \
                                 pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
                        git-(upload|receive)-pack))$" \
        /opt/git/libexec/git-core/git-http-backend/$1

# Anything not matched above goes to displayable gitweb interface
ScriptAlias /git /opt/git/cgi-bin/gitweb.cgi/

The result is the ability to push/pull:

me@machine /tmp/eddies $ git pull
Already up-to-date.

me@machine /tmp/eddies $ touch changedFile

me@machine /tmp/eddies $ git add .

me@machine /tmp/eddies $ git commit -am"commiting change"
[master ca7f6ed] commiting change
 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 changedFile

me@machine /tmp/eddies $ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 239 bytes, done.
Total 2 (delta 1), reused 0 (delta 0)
To http://mysecretdomain.com/git/eddies
   0f626a9..ca7f6ed  master -> master

And you can browse those changes online.. gitweb provides a browsable interface

Source: http://repo.or.cz/w/alt-git.git?a=blob_plain;f=gitweb/README

Eddie

Posted 2010-10-16T03:16:51.520

Reputation: 241

When I run the IMPORTANT line about the user, line 7, I get "SetEnv takes 1-2 arguments, an environment variable name and optional value to pass to CGI." -- why? – hhh – 2012-06-12T16:29:54.633

I would guess that value is empty, so setenv only sees 0 arguments. Because the apache uses a redirect rule it is possible REMOTE_USER is empty, so we grab the REDIRECT_RMEOTE_USER. You should be able to make the assignment optional if RMEOTE_USER is already defined (or rather is REDIRECT user is empty). http://httpd.apache.org/docs/2.0/mod/mod_setenvif.html#setenvif

– None – 2012-06-12T20:27:06.080

7

To enable a "git push" over http, you have to enable WebDAV on the webserver. To do that for Apache Webserver, simply edit the configuration file:

vim /etc/httpd/conf/httpd.conf

Then search for the line starting with:

<Directory "/var/www/html">

Add the following line just after it:

Dav On

Make sure you have the following line also in httpd.conf uncommented:

LoadModule dav_fs_module modules/mod_dav_fs.so

After that you are ready. Restart Apache Webserver using:

service httpd restart

Also make sure to make all the git repository files on the server be writable by the pache:apache user and group using:

chown -R apache:apache /var/www/html/your_git_repository

Otherwise, failing to set correct permissions will result in "PUT error: curl result=22, HTTP code=403" when performing a "git push".

Now simply do a "git push" from your client machine and all should work.

Basil A

Posted 2010-10-16T03:16:51.520

Reputation: 300

Note, if users get past this hurdle, but see an error in the apcahe logs about receive-pack http://stackoverflow.com/questions/792611/receive-pack-service-not-enabled-for-git/7150380#7150380

– None – 2011-08-22T16:16:52.563

2This will work, but DAV is not required, and actually performs much slower than smart-http. – None – 2011-08-24T14:56:45.283

4

You can't push on a repository you cloned through HTTP. You need to update the URL to either a ssh:// or a git:// type URL.

The Mighty Rubber Duck

Posted 2010-10-16T03:16:51.520

Reputation: 164

I used the same clone command. It worked before until I made the wrong deletion.... – None – 2010-10-16T04:25:23.647

what do you have with git remote -v ? – The Mighty Rubber Duck – 2010-10-16T06:11:47.173

Not entirely true. You can push back to repositories, assuming DAV is enabled. – None – 2011-02-17T20:28:36.293

6This is incorrect. Git since 1.6.6 supports smart http pushes and pulls using apache and git-http-backend. – None – 2011-08-22T13:40:32.067

3

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

Deepak

Posted 2010-10-16T03:16:51.520

Reputation: 131

Note: I used this method and it solved my issue - however I thought storing the password in the config file seemed wrong, so I left it off (hoping to be prompted for it), and was able to use it as such. – chris – 2013-07-10T14:45:24.630

git remote set-url origin ... works as well. – Maximilian Hils – 2014-05-01T14:14:19.677

1

I had the same problem with push operation with git-http-backend, ldap authentication config.
Finally I've found the solution and describe it in this serverfault question

Maybe it will help someone with similar problem.

gaspar

Posted 2010-10-16T03:16:51.520

Reputation: 111

0

Great

i had other errors but it works!

i try to explain:

BUT how to hide the password from the text at the push message?

user201304010101

Posted 2010-10-16T03:16:51.520

Reputation: 1

-1

This can also happen if you entered a wrong password.

sacha

Posted 2010-10-16T03:16:51.520

Reputation: 101

I've never seen that: I always get fatal: Authentication failed first – Rup – 2012-04-18T12:08:22.013