My Standard Operating Procedure (SOP) for dealing with Merge Conflicts in Git

Rinkesh Patel
3 min readJul 10, 2022

In this article, I am sharing my Standard Operating Procedure (SOP) to deal with merge conflicts in Git. Don’t worry! You don’t need to be an expert in Git to use this technique. I execute this on a daily basis in my role of software engineer at Immediation Platform Pty Ltd. This represents how I matured in terms of dealing with conflicts, not just code conflicts, but real-world conflicts as well. It also represents the journey of four years. My goal was to deal with merge conflicts like an algorithm, all decision-making logic is defined well before dealing with problems.

This is a general SOP, so you can apply it to GitHub as well. As both GitHub and Gitlab uses Git under the hood but do certain things differently like (Pull Request vs Merge Request).

What you need?

  1. Atom editor
  2. VS Code
  3. Gitlab/GitHub

Standard Operating Procedure

  1. Commit your changes: break down changes into atomic commits or logical groups: Just use the VS Code’s support for Git. Atomic commits will ensure that you’re not dealing with a large number of conflicts at a time. This will also ensure that you can easily deal with conflicts, as you can undo commits easily.
  2. Sync with the main branch: Pull other’s changes: git pull origin main
  3. Conflicts: how do they look like?
Fig. 1. How does conflict look like on command line?
  • Command line
Fig. 2. How does conflict look like in a file?
  • Files?

4. Open atom editor:

Fig. 3. 5 key points of the Standard Operating Procedure
  • Deal with conflicts file by file
  • Check the number of conflicts per file first
  • Start from file with the lowest number of conflicts and move to the file with the highest number of conflicts
  • All conflicts will have these options and markers: Your change, Their change, Where the HEAD of your branch is, Where the incoming branch’s changes are.
  • In a file, go from top to bottom, one conflict at a time.
  • Be consistent in your choices in a file
  • If your changes are more than their changes, then select your changes and copy/paste their changes.
  • If their changes are more than yours: then select their changes and copy/paste your changes
  • In a file, do not select their changes and your changes: Either all their changes or all your changes. This way you can ensure that certain problems are avoided: broken <div> tags in HTML, mismatches in brackets in JavaScript, missing brackets in JavaScript. This will also ensure that there are the least number of broken builds due to your merges.

4. Save the files in atom editor

5. In VS Code, Complete the merge, keep the message as it is.

6. Double check that the code is working on your local after dealing with conflicts.

7. If the code is working fine, then push to the upstream branch (main, master or whatever it is).

What Next?

Fig. 4. VS Code Three-way Merge Editor
Fig. 5. From where to enable VS Code Three-way merge editor?
  1. VS Code Three Way Merge Editor: With this exciting release, VS Code has really ramped up their game as far as dealing with merge conflicts is considered. Planning to say goodbye to Atom and use VS Code Three-way merge editor.

Please feel free to leave your thoughts. Thanks for reading.

--

--

Rinkesh Patel

A persistent problem solver trying to dig deeper into day-to-day challenges in Software Engineering and share insights. Love simple and effective solutions.