| CARVIEW |
Guides: Dealing with errors when pushing
It says “error: failed to push to ‘git://github.com/me/myrepo.git’” when I push. What gives?
Addresses that start with git:// are read only. In order to push, you must use the “git@github.com:me/myrepo.git” address listed as “Push URL” in the repo info for your repository.
error: “failed to push some refs to ’git@github.com:me/myrepo.git”
As a consequence of rewriting history or reset-ing to not current head
You might get this error after rewriting history in your local repo or reset-ing to not current head. Try to run git pull first. If it doesn’t work and your tree looks (gitk --all) like:
A—B—C <— master
/
o—o—X
\
Y-Z <— remotes/origin/master
try to rewrite it with (assuming you’re on the master branch):
git rebase origin/master
which should make:
A’—B’—C’ <— master
/
o—o—X—Y—Z <— remotes/origin/master
If you’re absolutely sure that your local branch is the correct one and you want to drop all diverging commits on the remote, you can use the following command.
Warning: this will not only destroy the history on the remote, it might also give an error message to anyone who updates from the same remote (depending on how much history you rewrite). Use this only as the very last resort.
git push —force origin master
As a consequence of renaming branches clashing with existing branches
Let us say you have a local branch ‘demo’ which has been pushed to github. You can rename the local branch from ‘demo’ to ‘demo/base’ and try pushing that and you will get an error like this:
error: 'refs/heads/demo' exists; cannot create 'refs/heads/demo/base' error: failed to lock refs/heads/demo/base To git@github.com:user/repos.git ! [remote rejected] demo/base -> demo/base (failed to lock) error: failed to push some refs to 'git@github.com:user/repos.git'
The trick is to delete the origin/demo branch (assuming ‘origin’ is github) first before pushing:
$ git push origin :demo $ git push origin demo/base
error: src refspec does not match any.
this is followed by the previous “failed to push some refs” error, which looks coincidental here.
Forcing didnt help either.
