Search code examples
gitgithubgit-mergegit-checkoutgit-merge-conflict

Resolve `git merge master` conflicts after doing `git checkout master --patch`


To be able to merge my local branch with master by a pull request, I'm trying to update my local branch with the latest modification on master. Since conflicts are complicated, I used this command to hand pick chunks of code modifications:

git checkout master --patch

Even after doing so, I cannot merge my local branch into master by a pull request due to conflicts. Also running this command, might not work due to complex conflicts:

git merge master

I ran out of options, how can I update my local branch with latest modifications on master without messing up anything?


Solution

  • Problem got resolved.

    I run command

    git checkout master --patch
    

    and I inspect code hunks one by one. This way, my local branch becomes reviewed and approved. Having done so, I need to keep the changes in my local branch when doing final merge by -X ours option:

     git merge master -X ours
    

    Then I can see the merge details by -m option just to double-check the merge:

    git show -m 7060e
    

    Now the merge is fine, even with complex conflicts. Now my pull request shows no conflicts anymore.