gitgithubrebaseconflict

Rebasing on master without merging every conflict of each commit of feature branch


I want to rebase my branch onto main. My feature branch is 40 commits ahead of the master branch.

When I do a git rebase main

I need to solve the merge conflict for the first commit, when that is done I :

git add MODIFIED_FILES
git rebase --continue

and I end up solving the conflicts of my 2nd commit. I simply cannot resolved 40 merge conflicts even that all of those first commits are rather obsolete compared to the latest development of my branch.

Is there a way to git rebase by doing solving the conflicts on only my latest branch's commit.


Solution

  • Finally found a solution to my problem :

    1/ Squash my X number of commits (commit id <specific_commit>) in my feature branch first :

    git rebase -i <specific_commit>
    git push -f
    

    By doing this your 40 commits become 1 in your feature branch history

    2/ I rebase onto main by solving 1/2 conflicts only

    # make sure that main is up to date
    git rebase main
    # solve conflicts
    git rebase --continue
    # might need to solve conflicts twice
    git push -f
    

    By doing this I get the linear history of the main branch into my feature branch which would make PR ready to be merged afterwards by the repo's maintainer.