When Git tells you it failed to push some refs

April 25, 2008 by Ed Spencer · 23 Comments 

I received an unhelpful error while trying to push to a repository on Github today:

git push
To git@github.com:user/repo.git
! [rejected] branchname -> branchname (non-fast forward)
error: failed to push some refs to 'git@github.com:user/repo.git'[/code]
In case you ever have the same problem, all you have to do is a quick git pull first, then you can carry on as normal. Easy when you know how...

Related posts

About Ed Spencer
Software Architect at Sencha Inc where I lead the development of Ext JS and supporting projects. A longtime lover of JavaScript and related geekery, currently living in Palo Alto.

Comments

23 Responses to “When Git tells you it failed to push some refs”
  1. jpemberthy says:

    I ran the

    git pull git@github.com:user/repository.git

    And I’m getting the:

    “Automatic merge failed; fix conflicts and then commit the result.”

    :( and then, i can’t push >_< '

    Thanks in advance!

  2. jpemberthy says:

    Dammit! XD, I forgot the question man, How are u running the pull command? XD

  3. Edward Spencer says:

    You need to fix any conflicts, then commit, then push. Run git status to find all files that couldn’t be merged automatically, edit each of them to fix them, then git add . and git commit.

    You should then be able to git push (though you may have to git pull again first).

    If you’ve named your origin already you should just be able to run “git pull” without naming the source. If you’re on a branch you may have to type “git pull origin branchname”.

  4. jpemberthy says:

    Hi, thank you, I solved my problem setting the core.autocrlf to false!

    Thanks!

  5. graham o'regan says:

    hi – was struggling to find a simple explanation for manual merging conflicts, simple as it is your comment explained it best!

  6. skillet-thief says:

    Hey, thanks. Knowing this is sure a lot better than not knowing it!

  7. Randy J. Hunt says:

    A life saver. Thanks!

  8. Anonymous says:

    Thanks. I was totally confused.

  9. Anonymous says:

    good job!

  10. Anonymous says:

    It’s not that simple if you then get:
    You asked me to pull without telling me which branch you
    want to merge with, and ‘branch.master.merge’ in

  11. Edward Spencer says:

    “if you then get:
    You asked me to pull without telling me which branch you want to merge with”

    If this happens to you, you need to specify the branch you want to pull. This will normally be master, as in:

    git pull origin master

  12. scottmotte says:

    Thanks.

  13. Harishankaran says:

    Thanks :) Short and sweet post :) Worked like magic :)

  14. James says:

    These are my favorite blog entries. They come up in the top of a Google search, they are short and sweet, and they work.

    Rock on.

  15. Amos Wenger says:

    What more to say? I know I couldn't be disappointed this soon by git. Thanks a million =)

  16. skumar says:

    Hi,
    Thanks. Really helps me but wasted some time without knowing this.

  17. Anonymous says:

    Thank you.

  18. Jess says:

    very useful, thank you

  19. Jay says:

    When I do the “git pull origin master”, I come up short with this:

    fatal: Couldn’t find remote ref master

    How can that be?

  20. Chris says:

    Thanks for this post. No I think I get it.

  21. Bryce says:

    That’s a good quick fix for maybe 90% of the cases, but it can cause problems.

    Example: I did git-rebase to remove an unwanted commit, and when I tried to push it gave me the error. When I did git-pull to resolve it, the unwanted commit came back. I’m still looking for a solution that actually fixes the originating branch.

  22. Bryce says:

    I found a deeper explanation of branch conflicts, for those who need it.

    http://www.bonsai.com/wiki/howtos/vcs/git_remote_resolve/

  23. vaibhav says:

    Hi,

    When I try to push the changes I get the below error message. I’m able to do a clean pull and git status shows no conflicts. Any help will be appreciated. thanks in advance

    $ git status
    # On branch experimental
    nothing to commit (working directory clean)

    $ git push ssh://abc@localhost:29418/httpd-2.2.15 HEAD:refs/for/experimental
    abc@localhost’s password:
    Total 0 (delta 0), reused 0 (delta 0)
    To ssh://abc@localhost:29418/httpd-2.2.15
    ! [remote rejected] HEAD -> refs/for/experimental (no new changes)
    error: failed to push some refs to ’ssh://abc@localhost:29418/httpd-2.2.15′

    Then i do:
    $ git pull ssh://abc@localhost:29418/httpd-2.2.15
    abc@localhost’s password:
    From ssh://abc@localhost:29418/httpd-2.2.15
    * branch HEAD -> FETCH_HEAD
    Already up-to-date.

    $ git status
    # On branch experimental
    nothing to commit (working directory clean)

    Thanks!!

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!