Rejected non fast forward-Git push rejected “non-fast-forward”

77.7K    Asked by MahimaKondo in Devops , Asked on Jul 18, 2021

 I am fairly new to git yet currently using it to manage our code in a team environment. I had some rebasing issues and I fixed them using

git checkout --ours filename.txt
git add filename.txt
git rebase --continue

Now I wish to push my changes, and so running the following command

$ git push origin feature/my_feature_branch

gives me the following error:

To ssh://git@coderepo.com:7999/repo/myproject.git
 ! [rejected]        feature/my_feature_branch -> feature/my_feature_branch (non-fast-forward)
error: failed to push some refs to 'ssh://git@coderepo.com:7999/repo/myproject.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Merge the remote changes (e.g. 'git pull')
hint: before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

What can I do to get rid of the error? What does git push rejected non-fast-forward mean?

P.S.: I am avoiding to use the --force option as much as possible.

Answered by Natun yadav

It seems like, there were new commits being pushed between your last git fetch and git push. In this case, you are required to repeat your steps and rebase my feature_branch one more time.

git fetch
git rebase feature/my_feature_branch
git push origin feature/my_feature_branch

After the git fetch I recommend examining the situation with gitk --all. 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.



Your Answer

Answer (1)

The error message "Rejected Non Fast Forward" indicates that your Git push was rejected because it attempted to push changes that aren't a fast-forward merge. This typically occurs when you're trying to push changes to a branch that has been updated on the remote repository since you last fetched or pulled changes.


To resolve this issue, you need to synchronize your local repository with the remote repository before pushing your changes. You can do this by fetching the latest changes from the remote repository and then rebasing or merging your local changes on top of them.

Sure, here's a rewritten version of the answer:

The error message "Rejected Non Fast Forward" indicates that your Git push was rejected because it attempted to push changes that aren't a fast-forward merge. This typically occurs when you're trying to push changes to a branch that has been updated on the remote repository since you last fetched or pulled changes.

To resolve this issue, you need to synchronize your local repository with the remote repository before pushing your changes. You can do this by fetching the latest changes from the remote repository and then rebasing or merging your local changes on top of them.

Here's how you can do it:

Fetch the latest changes from the remote repository:

git fetch

Merge the remote changes into your local branch:

git merge origin/

Resolve any merge conflicts if they occur.

Finally, push your changes to the remote repository:

  git push

By following these steps, you should be able to push your changes without encountering the "Non Fast Forward" error.

7 Months

Interviews

Parent Categories