DEV Community

John McDonald
John McDonald

Posted on

How to Resolve Merge Conflicts Quickly, Every Time.

How to Fix Merge Conflicts

Alt Text
You have been working on a big nice new feature for a few days, or even weeks. All the code is refactored, all the comments are useful, no console prints or debugger lines to be found. It's all ready to ship. You make a pull request. It's almost there. SMACK You have unresolved conflicts. Please fix these before continuing.

The pain is immediate and intense.

Well not to worry. This is a quick step by step guide on how to handle conflicts when merging your branch into, for example, develop. It's simple and foolproof. Here we go.

  1. Do the merge and resolve the conflicts locally:

    git fetch
    git checkout origin/DESTINATION
    git merge origin/SOURCE
    
  2. resolve conflicts...

    • Commit File(s)

      git add
      git commit

  3. Push the merge up as a new branch:

    git push origin HEAD:refs/heads/branch-with-conflicts-resolved
    
  4. Create new PR in Bitbucket and merge it. You have two options to finish
    the merge now that you have resolved all conflicts.

    Option 1.

    Source:       <branch-with-conflicts-resolved>
    Destination:  DESTINATION
    

    Or...

    Option 2.

  - First PR:

        Source:       <branch-with-conflicts-resolved>
        Destination:  branch

  - Complete that PR. Then in another PR:

        Source:       branch
        Destination:  DESTINATION
Enter fullscreen mode Exit fullscreen mode
  1. Now you have resolved your conflicts and merged. :-)

It may seem trivial now, but this is one of the most confusing and frustrating things for developers working in a large agile team environment, where the develop and main branches are changing hour to hour, and week to week, respectively. Hope you are well and happy coding!

Top comments (0)