How to handle Git merge strategies

· Category: Git

Short answer

Git merge strategies determine how divergent histories are combined; use -s to specify one during a merge.

Steps

  1. Recursive merge (default):
git merge feature
  1. Ours strategy (keep current branch changes):
git merge -s ours old-feature
  1. Resolve conflicts favoring one side:
git merge -X theirs feature
  1. Octopus merge (multiple branches):
git merge branch1 branch2 branch3

Tips

  • -X ours and -X theirs resolve conflicts automatically for each file.
  • Ours strategy records a merge without taking any content from the other branch.
  • Octopus is useful for combining multiple independent features at once.

Common issues

  • Incorrect strategy choice can silently discard wanted changes.
  • Octopus fails if there are conflicts between the merged branches.