Git Confusion about merge algorithm, conflict format, and interplay with mergetools
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
Git's merge system has three layers that developers often conflate: the merge algorithm (how Git computes what changed), the conflict format (how Git displays unresolvable differences in your files), and mergetools (external programs that help you resolve conflicts). Understanding each layer separately clears up most merge confusion. The algorithm decides what conflicts exist, the format controls what you see in the file, and the mergetool provides a visual interface to pick the right resolution.
Merge Algorithms
Git supports several merge strategies, each with its own algorithm for combining changes:
Recursive (default for two branches)
The recursive strategy finds the common ancestor of both branches and performs a three-way merge. If there are multiple common ancestors (criss-cross merges), it recursively merges the ancestors first to create a virtual base. This handles most cases correctly.
ORT (Ostensibly Recursive's Twin, Git 2.33+)
ORT is a rewrite of the recursive strategy that is faster and handles edge cases (directory renames, file/directory conflicts) more correctly. It became the default in Git 2.34+.
Octopus (default for 3+ branches)
Ours
Conflict Format: merge vs diff3
When Git cannot auto-merge, it writes conflict markers into the file. The default format shows two sides:
Default (merge) Format
You see what HEAD has and what the feature branch has, but not what the common ancestor had. This makes it hard to understand the intent of each change.
diff3 Format (Recommended)
- You run: git merge feature
- Git picks the merge ALGORITHM (recursive/ort)
- Algorithm finds conflicts it cannot auto-resolve
- Git writes conflict MARKERS in the FORMAT you configured (merge/diff3/zdiff3)
- You either: a. Edit the file manually (read the markers, fix, save) b. Run
git mergetool→ opens the MERGETOOL with LOCAL/REMOTE/BASE/MERGED - Mark resolved: git add file.js
- Complete: git merge --continue
Recommended Configuration
Common Pitfalls
- Not using diff3/zdiff3: The default two-way conflict format hides the common ancestor, making it impossible to understand the intent of each change. Always enable
diff3orzdiff3. - Confusing strategy with format: Changing
merge.conflictstyledoes not change how Git computes the merge. It only changes how conflicts are displayed. The algorithm (recursive,ort) is a separate setting. - Mergetool
.origfiles: By default,git mergetoolcreates.origbackup files. These clutter your repo and get accidentally committed. Setmergetool.keepBackup false. - Aborting a merge incorrectly: Use
git merge --abortto cleanly cancel a merge in progress. Do notgit checkout .orgit reset --hardduring a merge — these may leave the repo in an inconsistent state. - Assuming the mergetool resolves automatically: Mergetools present the conflict visually but you still choose the resolution. Closing the tool without editing marks the file as resolved with whatever content it had, potentially keeping conflict markers.
Summary
- Merge algorithms (recursive, ort, octopus) determine how Git combines changes and detects conflicts
- Conflict format (merge, diff3, zdiff3) controls what you see in conflict markers — use
zdiff3for the best experience - Mergetools (VS Code, vimdiff, IntelliJ) provide visual interfaces for resolving conflicts using LOCAL, REMOTE, BASE, and MERGED files
- These three layers are independent — configure each separately
- Always enable
diff3orzdiff3to see the common ancestor in conflict markers
Related reading
- Given 2 sorted arrays of integers, find the nth largest number in sublinear time
- Given a 1 TB data set on disk with around 1 KB per data record, how can I find duplicates using 512 MB RAM and infinite disk space?
- Given a bitonic array and element x in the array, find the index of x in 2logn time
- Given a list of date ranges, find a date which occurs maximum times
- Git Corrupt loose object
- Git Could not resolve host github.com error while cloning remote repository in git
- Given a list of dictionaries, how can I eliminate duplicates of one key, and sort by another
- Given a list of numbers and a number k, return whether any two numbers from the list add up to k

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.