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
- Recursive merge (default):
git merge feature
- Ours strategy (keep current branch changes):
git merge -s ours old-feature
- Resolve conflicts favoring one side:
git merge -X theirs feature
- Octopus merge (multiple branches):
git merge branch1 branch2 branch3
Tips
-X oursand-X theirsresolve 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.