How to solve the error of git push rejected non fast forward?

494    Asked by BrianKennedy in Devops , Asked on Jul 25, 2023

I am totally a novice to git. However I am recently deploying it to handle the code in the team environment. I have faced few rebasing problems but I solved the error utilizing

Git checkout - - ours filename.txt
Git add filename.txt
Git rebase - - continue
Now I want to push the alterations, and thus I am executing the below-given command.
$ git push origin feature/my_ feature_branch
However, I am receiving the belo-mentioned 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.

How do I fix this error? Also, what is the meaning of git push rejected non-fast-forward?

Answered by Bruce Benedict

Git push rejected non-fast-forward error occurs when git is not able to do the desired modifications to the remote repository. This often occurs due to the commitement being lost or when someone else attempts at pushing the identical branch like you. When you perform a commit in a single project and then mistakenly push the commit, through bypassing code review,to a different project, the commit will fail displaying the error message ‘non-fast-forward’. If you wish to fix the problem you must verify the push statement and ensure that commit is being pushed to the right project. It looks like there were fresh commits being pushed between the previous git fetch and git push. Here, you are needed to do the steps again and rebase my_feature_branch again.Git fetch

Git rebase feature/my_feature_branch
Git push origin feature/my_feature_branch
Post git fetch you can examine the condition with gitk - - all.

The devOps certification training offered at Janbask saves you from the exhaustion of travelling to the physical location. The training offers an overall devOps discipline preparation by touching all the core concepts, and methods that devOps engineer certification calls for. The company imparts fundamental to advanced lessons needed to be job=ready in the competitive market.



Your Answer

Interviews

Parent Categories