How can j troubleshoot the issue of [rejected] main -> main(non-fast-forward) in git?

357    Asked by BernadetteBond in Devops , Asked on Dec 15, 2023

I was assigned to a project under a team that is collaborating on a project related to Git, however, during the process of merging a feature branch into the main branch I encountered an issue that tells! [Rejected] main -> main(non-fast-forward). How can I troubleshoot this particular issue? 

Answered by Ashish Mishra

In the context of DevOps, when you face the error that shows [rejected] main -> main(non-fast-forward), it generally means that the main branch has progressed with commits due to the feature branch diverging. To troubleshoot this particular issue, you can utilize a rebase or a merge commit:-

To resolve using a merge commit, here is the example given:-

Git checkout main

Git merge – no—FF feature _ branch

To resolve using rebase, you can use the following command:-

“ git checkout feature_ branch

   Git rebase main

   Git checkout main

   Git merge feature_ branch”

If you choose the method of merge commit then it will preserve a clear history by creating a new commit. On the other hand, the rebase method applies the commit from the branch feature on top of the main branch.



Your Answer

Interviews

Parent Categories