Search code examples
gitgithubversion-controlmergegit-merge-conflict

How to do Git conflict resolution using a separate resolution branch?


I have following branches on my local:

  1. master
  2. branch-a
  3. branch-b
  4. branch-c
  5. dev

I created PR (Pull Request) for branch-a (PRA-1), branch-b (PRB-1), branch-c (PRC-1). My colleagues finished reviewing my code. Since I know that branch-a, branch-b, branch-c are going to conflict each other, I create a conflict-resolution branch.

I base conflict-resolution from master and continue to merge branch-a, branch-b, branch-c while resolving any conflicts. Then once all of them are complete, I merge this conflict-resolution branch into branch-a, branch-b, branch-c.

Now that my initial pull request is code reviewed, I want my colleagues to review conflict-resolution for branch-a (PRA-2), branch-b (PRB-2) and branch-c (PRC-2) in their respective second pull requests.


Solution

  • If you want, you can use git rerere (https://git-scm.com/blog/2010/03/08/rerere.html and http://git-scm.com/docs/git-rerere). This commands let you save conflict resolutions for done again the resolution when you want. So, in order to save the conflict resolution you must merge your three branches in master branch. But you don't want because you wait for this merge. I advise these steps :

    Enable git rerere cache with :

    git config --global rerere.enabled true
    

    Create new branch from master

    git checkout master
    git branch resolution_branch
    

    Merge and resolve conflicts of the three branches

    git merge branch-A
    # You resolve conflict
    
    git merge branch-B
    # You resolve conflict
    
    git merge branch-C
    # You resolve conflict
    

    Now, when you will merge these branches Git will resolve conflict. However, You must to add file to index for explicit resolution. If you want that Git add automaticaly file in the index :

    git config --global rerere.autoupdate true