Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git pull says up-to-date but git push rejects non-fast forward

I've just pulled a new branch, made some local changes, committed and tried to push. I was given this error: ! [rejected] groups -> groups (non-fast forward) So I tried a to pull but was told Already up-to-date.

Here's what I get pulling then pushing.

~/dev$ git pull origin groups Already up-to-date. ~/dev$ git push origin groups To /mnt/ebs/git/repo.git  ! [rejected]        groups -> groups (non-fast forward) error: failed to push some refs to '/mnt/ebs/git/repo.git' 

Can anyone explain how this can be happening and how I can fix it?

like image 372
Jake Avatar asked Nov 30 '10 09:11

Jake


People also ask

How do I fix a non-fast-forward in git?

If you do a commit in one project and then accidentally push this commit, with bypassing code review, to another project, this will fail with the error message 'non-fast forward'. To fix the problem you should check the push specification and verify that you are pushing the commit to the correct project.

What does rejected non-fast-forward mean in git?

Git push rejected non-fast-forward means, this error is faced when git cannot commit your changes to the remote repository. This may happen because your commit was lost or if someone else is trying to push to the same branch as you. This is the error you face.

Why is git push being rejected?

A commit gets rejected and causes a failed to push some refs to error because the remote branch contains code that you do not have locally. What this means is that your local git repository is not compatible with the remote origin. Based on the above, your local machine is missing commits C and D.


2 Answers

When you pulled the branch, did you use the "--track" option (in order to keep you local branch tracking the remote branch). If you did not, it can explain that the "merge" command that does not work.

You can do the merge manually:

git fetch git merge origin/groups 

To compare local and remote repos, I suggest you this command (add it in an alias, it is usefull):

git log --graph --oneline --all --decorate 

It will print the project history tree, showing the branch labels. So you will see where your branch and the origin branch diverge.

Note: if you want to preserve a linear history, instead of a "merge", you can do a "rebase" of your local branch on the remote before pushing:

git rebase origin/groups git push origin groups 
like image 161
Benoit Courtine Avatar answered Oct 07 '22 18:10

Benoit Courtine


I came here with a different problem.

My git was set up to push all branches. I was on a branch FOO, but it was also trying to push master, which was not up to date. The trick was noticing it was trying to push master:

To [email protected]:repo  ! [rejected]        master -> master (non-fast-forward) 

I added the following to my .gitconfig to only push the current branch by default:

[push]     default = current 
like image 38
dfrankow Avatar answered Oct 07 '22 19:10

dfrankow