If you have been working on a feature branch for an extended period of time and would like to get new work from the main branch brought into your feature branch, use the following method to prevent merge conflicts and simplify the timeline.
git checkout main
git pull origin main
git checkout your-feature-branch
Now choose to merge or rebase as a final step:
//merge method
git merge main
//resolve any conflicts
git commit
git merge method – will create a new “merge commit” at the end that ties the two histories together. This preserves chronological histories in non destructive manner.
//rebase method (my preference now)
git rebase main
//resolve any conflicts
git rebase --continue
git rebase method – will rewrite the history so that you get the main branches missing commits but rewrites your commits so it looks like your work was started and completed after all of main branches commits.
Now you can create a pull request and get your feature added to the main branch with no issues.