By now I knew enough about Git to easily deal with the “error: failed to push some refs” error.
Just pull first, fix any merge problems, and then push.
But this morning I still got the error after doing a pull, then a push to the Bixo project on GitHub.
It turns out I need to read the git output more closely. The error message said:
! [rejected] master -> master (non-fast forward) error: failed to push some refs to 'git@github.com:bixo/bixo.git'
But I’m working in a branch (called ‘fetch-flow’). And the “git push” command will try to push all of the branches. But “git pull” only pulls the current branch.
So I had to “git checkout master” to switch to the master branch, then “git pull” to bring that up to date, then “git checkout fetch-flow” to switch back to my branch.
And now my git push works fine. Note that the push did work, in that my ‘fetch-flow’ branch was pushed – it’s just that the auto-push to master failed, and that made me think my entire push had failed.
Great! thanks.
Hey, thank you, that really helped, had some branches too, with the same problem on 2 branches. Fixed by your guide. Thanks once again!
Thank you for your artcle
Thanks for the tip. Helped me get past this. However… really? This is the way git works? I work in a shop with several branches. Every time I want to push I’ve really got to checkout each branch that’s ahead of my repo and pull each one individually?
Hi Lance,
I’ve revised the post above to be more accurate – your push works, you just get a confusing error about the other branches that git tries to auto-push.
— Ken
Interesting. Thanks for the update. Yes, that is a confusing error…
For whatever reason, by default
git push
pushes to all branches on the remote. To set this to the default that you’re expecting (and that really seems the only sane and reasonable default to me, but I digress), you can usegit config remote.origin.push HEAD
. But meanwhile, since you may wind up using git from other machines and forget that the default behavior is broken, you should probably always just specify the remote and branch explicitly.So, using your example here, you would use:
The problem with this is that if you mistype your branch, you could wind up creating a new branch on the remote with the typo, e.g. something like
fletch-flow
. So that brings us to what is likely the bestgit push
habit to get into:This will push only the current branch to a branch of the same name on the remote.
Hope this helps. This is all in the
git push
docs, but it really isn’t very clearly or prominently presented.error : src refspec test does not match any.
fatal : The remote end hung up unexpectedly
error : failed to push some refs to ‘git@github.com: {username}/{projectname}.git’
Check the solution here….It might help someone
http://www.codingdefined.com/2014/07/error-when-git-push-src-refspec-test.html