Welcome to merge-strategies

This is an auto-generated documentation file.


Merge Strategies

Git supports multiple strategies to resolve merges between branches. These determine how the merge is performed when automatic reconciliation is needed.


1. Recursive (default)

  • This is Git’s default merge strategy.
  • It handles two heads (branches) and performs a three-way merge.
  • It can automatically resolve trivial conflicts and detect renames.

When to use:

  • Most common scenario: merging feature branches into main.

Command (implicitly used):

git merge feature
# or explicitly:
git merge -s recursive feature

2. Resolve

  • A simpler strategy than recursive, used only when the history is simple.
  • Does not support renames or complex conflict resolution.
  • Older strategy, rarely used now.

When to use:

  • Very basic branches with no file renames or criss-cross merges.

Command:

git merge -s resolve feature

3. Ours

  • This strategy favors the current branch's changes.
  • Conflicts are automatically resolved by discarding the incoming branch’s content.

When to use:

  • When you want to keep the current branch’s content no matter what.
  • Useful in complex situations like combining unrelated histories.

Command:

git merge -s ours legacy-feature

4. Octopus

  • Allows merging more than two branches simultaneously.
  • Useful for automatic merges of many topic branches.
  • Cannot handle conflicts; if one exists, the merge fails.

When to use:

  • Merging multiple simple branches (e.g., after parallel developments).

Command:

git merge -s octopus topic1 topic2 topic3

Summary Comparison

StrategySupports ConflictsBest ForNotes
recursiveYesDefault for two branchesHandles most use cases
resolveLimitedVery simple historiesNot recommended for modern Git usage
oursNo (favors current)Overwriting incoming changesKeeps current branch only
octopusNoMerging many branches at onceFails if conflicts arise