Git failed to push some refs – the multiple branch variant

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.

Advertisements

8 Responses to Git failed to push some refs – the multiple branch variant

  1. danone says:

    Great! thanks.

  2. Tosha says:

    Hey, thank you, that really helped, had some branches too, with the same problem on 2 branches. Fixed by your guide. Thanks once again!

  3. BillyJin says:

    Thank you for your artcle

  4. ljohnston says:

    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?

    • kkrugler says:

      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

  5. ljohnston says:

    Interesting. Thanks for the update. Yes, that is a confusing error…

  6. Seth Milliken says:

    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 use git 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:

    git push origin fetch-flow
    

    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 best git push habit to get into:

    git push origin HEAD
    

    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.

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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: