Rejected Non Fast Forward-Git Push Rejected “Non-Fast-Forward”
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:
! [rejected] feature/my_feature_branch -> feature/my_feature_branch (non-fast-forward)
error: failed to push some refs to 'ssh://firstname.lastname@example.org: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?
I found some useful instructions in the github help page and wanted to share them here. Sometimes, Git can't make your change to a remote repository without losing commits. When this happens, your push is refused. If another person has pushed to the same branch as you, Git won't be able to push your changes:
$ git push origin master
! [rejected] master -> master (non-fast-forward)
error: failed to push some refs to 'https://github.com/USERNAME/REPOSITORY.git'
To prevent you from losing history, rejected Master master non-fast-forward updates were rejected
Merge the remote changes (e.g. 'git pull') before pushing again. See the
'Note about fast-forwards' section of 'git push --help' for details.
You can fix this by fetching and merging the changes made on the remote branch with the changes that you have made locally:
$ git fetch origin
# Fetches updates made to an online repository
$ git merge origin YOUR_BRANCH_NAME
# Merges updates made online with your local work
Or, you can simply use git pull to perform both commands at once:
$ git pull origin YOUR_BRANCH_NAME
# Grabs online updates and merges them with your local work.