Git: push rejected non-fast forward
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
Thanks for posting this Tony! I encountered the same error, and your tip solved the problem perfectly.
Thank you for this help, i found it with one search in yahoo…. it solved my problem 😉
[…] for the tip goes to Tony at Rip’s Blog. Share and […]
Thank you for information. I had this problem in a remote branch, no branch master, and I solved it.
Whew, thanks!
+1.
Thanks.
Thanks, cool
Great tip. It solved the problem quickly. Thanks.
New to git. Thanks for the tip!
Thanks! You just saved my day as well.
Thans a lot ) it helped me
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.
When I pull:
CONFLICT (add/add): Merge conflict in ……..
Thanks, this saved me today. New to git. Still don’t git the concepts.
Thanks… this solve my problem 🙂
If it does not work for you, execute:
git checkout master
Thanks…
Thanks it helps me!
Thanks, it helped me a lot. 🙂
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)
Thx, it helped me 😀
Thanks it did the trick 🙂
I have the same problem as Rachel
Thanks for the post, saved me a few hours headache.
>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
I too have the same problem as Rachel
Thanx alot!!! This helped me
Super thanks.
Point learnt, is to sync both repositories first (pull) and then (push) the code to remote github.
Thanks.. this helped me 🙂
Thanks for this !
THANK YOU . i was researching for almost an hour. you did the first comprehensible solution to the problem.
This was very straight forward tip up to the point. Thanks a lot
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!
it worked! thanks..
thanks a lot, dude.
Thanks . It works..
thanks a lot dude!
Thanx a lot buddy 🙂
Thanx a lot hey, saved me a lot of time 🙂
Thanks, you saved my day. 😀