Rip's Domain

Git: push rejected non-fast forward

Posted in Git, TechSupport by rip747 on April 20, 2009

When trying to do a push to a repo, you might encounter the following error:

$ git push github master
To git@gitproxy:rip747/cfwheels.git
! [rejected]        master -> master (non-fast forward)
error: failed to push some refs to ‘git@gitproxy:rip747/cfwheels.git’

Don’t panic, this is extremely easy to fix. All you have to do is issue a pull and your branch will be fast-forward:

$ git pull github master
From git@gitproxy:rip747/cfwheels
* branch            master     -> FETCH_HEAD
Already uptodate!
Merge made by recursive.

Then retry your push and everything should be fine:

$ git push github master
Counting objects: 44, done.
Compressing objects: 100% (32/32), done.
Writing objects: 100% (32/32), 6.30 KiB, done.
Total 32 (delta 23), reused 0 (delta 0)
To git@gitproxy:rip747/cfwheels.git
1717535..1406e8c  master -> master

UPDATE: I ran into another instance of this that the solution above didn’t solve and have provided a solution below.

Another situation where you might run into this, is if you’re tracking a branch that is not the same name as the remote. For instance, say you have a remote branch called otherrepo/master and you already have a local master branch, so you checkout the otherrepo/master branch as othermaster locally. Now even though you do a pull, when you go to push, you will get the rejected error.

To get around this, you will have to specify the local branch in the push command using a colon (:) like so:

git push otherrepo othermaster:master

About these ads

40 Responses

Subscribe to comments with RSS.

  1. Mike said, on July 8, 2009 at 4:20 pm

    Thanks for posting this Tony! I encountered the same error, and your tip solved the problem perfectly.

  2. Ironman 2009 said, on September 9, 2009 at 3:28 am

    Thank you for this help, i found it with one search in yahoo…. it solved my problem ;-)

  3. […] for the tip goes to Tony at Rip’s Blog. Share and […]

  4. Prodis a.k.a. Fernando Hamasaki de Amorim said, on October 8, 2009 at 11:00 am

    Thank you for information. I had this problem in a remote branch, no branch master, and I solved it.

  5. Tim said, on January 11, 2010 at 10:10 pm

    Whew, thanks!

  6. konsty said, on January 12, 2010 at 8:23 am

    +1.
    Thanks.

  7. Venia said, on January 29, 2010 at 10:56 am

    Thanks, cool

  8. jeffreymuir said, on February 9, 2010 at 9:15 pm

    Great tip. It solved the problem quickly. Thanks.

  9. Chris said, on March 31, 2010 at 1:56 pm

    New to git. Thanks for the tip!

  10. Les said, on April 15, 2010 at 11:41 pm

    Thanks! You just saved my day as well.

  11. alexb said, on June 23, 2010 at 11:46 am

    Thans a lot ) it helped me

  12. PeEll said, on August 4, 2010 at 2:51 am

    This definitely fixed the problem! Now it’s time for me to figure out why my origin git repo had a change that affected 0 files and has a blank diff.

  13. NARKOZ said, on September 24, 2010 at 12:45 pm

    When I pull:
    CONFLICT (add/add): Merge conflict in ……..

  14. marlene said, on December 21, 2010 at 10:54 am

    Thanks, this saved me today. New to git. Still don’t git the concepts.

  15. eenx said, on March 30, 2011 at 3:23 am

    Thanks… this solve my problem :)

  16. Mangirdas said, on May 19, 2011 at 1:46 am

    If it does not work for you, execute:

    git checkout master

  17. sandeep said, on May 25, 2011 at 5:32 am

    Thanks…

  18. F G D said, on June 13, 2011 at 5:21 am

    Thanks it helps me!

  19. kiruban said, on November 29, 2011 at 9:03 am

    Thanks, it helped me a lot. :)

  20. Rachel said, on April 18, 2012 at 5:51 pm

    Doesn’t work for me.

    ‘git push heroku master’ gives me the note about fast forwards.

    ‘git pull’ says ‘Already up-to-date.’

    Somehow github broke heroku. ‘git remove -v’ says
    heroku git@heroku.com:appname.git (fetch)
    heroku git@heroku.com:appname.git (push)
    origin git@github.com:username/appname.git (fetch)
    origin git@github.com:username/appname.git (push)

  21. lx281 said, on April 24, 2012 at 1:57 am

    Thx, it helped me :D

  22. Hanynowsky said, on April 29, 2012 at 6:49 pm

    Thanks it did the trick :)

  23. Lucas said, on May 5, 2012 at 3:57 pm

    I have the same problem as Rachel

  24. M said, on May 15, 2012 at 11:52 am

    Thanks for the post, saved me a few hours headache.

  25. smartov said, on June 7, 2012 at 11:07 am

    >if you’re tracking a branch that is not the same name as the remote

    Thanks for this. I couldn’t figure out what’s wrong

  26. Delaney said, on June 21, 2012 at 10:42 am

    I too have the same problem as Rachel

  27. Mv68 said, on July 5, 2012 at 2:38 pm

    Thanx alot!!! This helped me

  28. Adithya said, on July 16, 2012 at 2:11 am

    Super thanks.
    Point learnt, is to sync both repositories first (pull) and then (push) the code to remote github.

  29. Ju Hwang Kim said, on July 18, 2012 at 2:36 am

    Thanks.. this helped me :)

  30. haxpor said, on August 18, 2012 at 5:05 am

    Thanks for this !

  31. samper said, on September 2, 2012 at 12:03 pm

    THANK YOU . i was researching for almost an hour. you did the first comprehensible solution to the problem.

  32. Wrushasen Dakhane said, on September 3, 2012 at 9:35 pm

    This was very straight forward tip up to the point. Thanks a lot

  33. Mihail said, on September 21, 2012 at 5:32 pm

    As simple as it needs to be!
    I’ve just read a couple to posts about this topic and this is just the one that works!

  34. bluebird said, on October 29, 2012 at 3:54 am

    it worked! thanks..

  35. Fabrício said, on November 4, 2012 at 11:31 am

    thanks a lot, dude.

  36. Mukesh said, on March 14, 2013 at 1:52 am

    Thanks . It works..

  37. anand babu said, on March 21, 2013 at 8:49 am

    thanks a lot dude!

  38. AMIT DHANKAR said, on May 2, 2013 at 1:22 pm

    Thanx a lot buddy :-)

  39. Likho said, on June 5, 2013 at 2:11 pm

    Thanx a lot hey, saved me a lot of time :)

  40. iamharsh said, on July 9, 2013 at 5:43 am

    Thanks, you saved my day. :D


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

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: