I made my own git repo on my server using git init --bare
. I added some files there and then cloned my repo from myserver by git clone http://www.example.com/mygit/repo
and it cloned perfectly. Now i want to push this directory by git push origin master
but it is returning code 22. I also added ssh public key of my PC to http://www.example.com/mygit/repo/.ssh/authorized_keys
but still i can't push into my repo.
-
Can you check your http error logs and see if any errors are showing there? – Matt Jennings Feb 01 '14 at 00:57
5 Answers
Just for the record, because this comes up high on google when searching "git-http-push failed return code 22":
With https git and htpasswd on the server, it seems that the user name sent includes the domain: user@domain.tld
, but the expected name is only user
.
The solution for me was to add this in ~/.netrc
:
machine host.domain.tld
login the_user_name
password the_password

- 1,199
- 9
- 4
-
In addition to this, I have this issue everytime with the a new clone. Need to add "the_user_name@" to the config file at the url setting. So url = https://stackoverflow.com/git/repository.git will become url = https://the_user_name@stackoverflow.com/git/repository.git – Hutjepower Jun 26 '15 at 13:53
Try to add this to your config file in the bare repository:
[http]
receivepack = true

- 3,768
- 5
- 33
- 42
-
1I tried this and it didn't work for me. I'm still looking for a solution. – Mirko Seifert Nov 19 '14 at 10:29
-
The error can depends from a lot of reasons. Using the server http log can be a lot of help. – Marcs Nov 19 '14 at 11:14
/repo/.ssh/authorized_keys
won't mean anything to your ssh daemon on your server: sshd will look for that file under the home of the user making the ssh query: /home/user/.ssh/authorized_key
Plus, if you are using https://... urls, you won't use ssh at all anyway. For an ssh url to work, you would need an Apache server properly configure to call the git-http-backend
script.
See for instance this git-http-backend question.
That is because you cloned using the http url and not the ssh url that is present on Github. And now you are trying to push using ssh which will not work. In such cases, git clone or git pull works but git push fails.
One solution is to clone using the ssh url which will be of the form git@github.com:username/repo-name.git You can find this url on ur Github repo when you click on SSH in "You can clone with HTTPS, SSH, or Subversion" message. And then make changes and do a git push. Make sure that the public key for your machine is present in your Github account.
Another way for the current situation to work would be to supply username and password when doing a Git push.

- 3,851
- 1
- 19
- 8
The trick for me was to enable WebDAV
I put it in LocationMatch:
<LocationMatch /git/.*\.git>
Dav On
AuthType Basic
AuthName "Git Verification"
AuthUserFile /etc/httpd/git/test.passwd
Require valid-user
</LocationMatch>

- 1
- 2