When to Use the Accept Ours Strategy
Understand when Accept Ours (keeping HEAD changes) is the right resolution strategy. Learn the git checkout --ours command equivalent.
Detailed Explanation
The Accept Ours Strategy
"Accept Ours" means keeping the version from your current branch (HEAD) and discarding the incoming branch's changes for that conflict block. This is equivalent to running git checkout --ours <file> on the command line, but applied to individual conflicts rather than the entire file.
When to Use Accept Ours
Your branch has the newer or more correct version:
- You fixed a bug that the other branch still contains.
- You updated a value that supersedes the incoming change.
- The other branch's change was experimental and should not be merged.
The incoming change was reverted or replaced:
- The feature from the other branch was abandoned.
- A newer implementation already exists in your branch.
Configuration divergence is intentional:
- Environment-specific configuration should remain as your branch defines it.
- Your branch targets a different deployment environment.
Accept Ours on the Command Line
For the entire file:
git checkout --ours path/to/file.txt
git add path/to/file.txt
For a specific merge strategy:
git merge -X ours feature-branch
Note: -X ours (strategy option) differs from -s ours (strategy). The -s ours strategy discards ALL changes from the other branch, not just conflicts.
Risks of Accept Ours
- You may lose legitimate changes from the incoming branch.
- If the incoming branch addressed a bug, that fix will be discarded.
- Team members who worked on the incoming branch may expect their changes to be included.
Best Practice
Before accepting ours, briefly review what the incoming branch was trying to accomplish. If their change addresses a real issue, consider Manual Edit to incorporate both the fix and your changes.
Use Case
You are merging an older feature branch into your branch that already contains a hotfix. The feature branch still has the outdated code, so you accept your version (ours) for all affected conflicts.