Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Devops
  3. Question
Devops

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

Asked by Mahima Kondo Jul 18, 2021 100.9K views 3 answers
Share

About this question

 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.

Your answer

3 Answers

Ranjana Admin JanBask Expert Latest answer

Answered on Jan 27, 2025

If you encounter the error "Rejected non-fast-forward" while trying to push changes to a Git repository, it means your local branch is out of sync with the remote branch. This happens when the remote branch has changes you don’t have locally. Here’s how to resolve the issue:

Steps to Solve:

1. Understand the Problem:

  • The remote branch has new commits, and Git won’t overwrite those changes with your push.
  • Git requires a “fast-forward” merge, meaning your branch must include all changes from the remote.

2. Fetch and Merge:

Run the following command to fetch the latest changes from the remote branch:

  git fetch origin

Merge the changes into your branch:

  git merge origin/

Resolve any merge conflicts that arise, commit the changes, and try pushing again:

  git push origin 

Pull Before Pushing (Alternative):

Use git pull to fetch and merge changes in one step:

  git pull origin 

Resolve conflicts if needed, commit, and then push:

  git push origin 

Force Push (Use with Caution):

If you are certain your changes should overwrite the remote branch, you can force push:

  git push origin  --force

This will replace the remote branch history, so ensure this is intentional.

Best Practices:

  • Always pull before pushing to avoid conflicts.
  • Communicate with your team to prevent overwriting others’ work when using --force.

This approach should help you resolve the issue effectively!

Was this helpful?

Ranjana Admin JanBask Expert

Answered on Apr 18, 2024

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.

Was this helpful?

More Devops discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest DevOps Blogs

Guides, tips and career advice on DevOps from JanBask experts.