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

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


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 )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 87 other followers