When to Use the Accept Theirs Strategy
Understand when Accept Theirs (keeping incoming branch changes) is the right choice. Learn the git checkout --theirs command equivalent.
Detailed Explanation
The Accept Theirs Strategy
"Accept Theirs" means keeping the version from the incoming branch and discarding your current branch's changes for that conflict block. This is the equivalent of running git checkout --theirs <file> on the command line for individual conflicts.
When to Use Accept Theirs
The incoming branch has a newer or better implementation:
- The other branch contains a more recent refactor.
- Their version follows updated coding standards.
- The incoming change was code-reviewed and approved.
You are pulling upstream changes:
- When rebasing your feature branch onto an updated main, the "theirs" version represents the team's agreed-upon state.
- Open source contributions: the maintainer's version should take precedence.
Your changes are no longer needed:
- You made a temporary workaround that the incoming branch properly fixes.
- Your change was a draft that the other branch completed.
Accept Theirs on the Command Line
For the entire file:
git checkout --theirs path/to/file.txt
git add path/to/file.txt
For a merge strategy option:
git merge -X theirs feature-branch
Important Nuance: Rebase Swaps Ours and Theirs
During git rebase, the meaning of ours and theirs is reversed. When rebasing your branch onto main:
- "Ours" = the commit being rebased onto (main)
- "Theirs" = your branch's commit being replayed
This is a common source of confusion. In a rebase context, if you want to keep your own changes, you actually need Accept Theirs.
Risks of Accept Theirs
- Your branch's specific changes are discarded for the conflicting block.
- If your changes addressed edge cases not covered by the incoming branch, those fixes are lost.
- Always verify that the incoming version handles all scenarios your code addressed.
Use Case
You are rebasing your feature branch onto the latest main branch. Main has undergone significant refactoring, and you want to adopt all the new patterns from main, accepting their version for most conflicts.