0
0
Gitdevops~10 mins

Ours vs theirs in conflicts in Git - Visual Side-by-Side Comparison

Choose your learning style9 modes available
Process Flow - Ours vs theirs in conflicts
Start merge
Conflict detected
Choose resolution
Use ours
Mark resolved
Complete merge
When a merge conflict happens, you decide which version to keep: 'ours' (your changes) or 'theirs' (incoming changes). Then you mark the conflict resolved and finish the merge.
Execution Sample
Git
git merge feature-branch
# conflict occurs
# resolve with ours: git checkout --ours <file>
# or with theirs: git checkout --theirs <file>
git add <file>
git commit
This sequence shows merging a branch, resolving conflicts by choosing 'ours' or 'theirs', then committing the resolution.
Process Table
StepActionConflict StateFile Content ChosenNext Step
1git merge feature-branchConflict detected in file.txtNone yetChoose resolution
2git checkout --ours file.txtConflict unresolvedOur version of file.txtStage file
3git add file.txtConflict resolvedOur version stagedCommit merge
4git commitMerge completedOur version saved in historyEnd
5git merge feature-branchConflict detected in file.txtNone yetChoose resolution
6git checkout --theirs file.txtConflict unresolvedTheir version of file.txtStage file
7git add file.txtConflict resolvedTheir version stagedCommit merge
8git commitMerge completedTheir version saved in historyEnd
💡 Merge ends after committing resolved version, either ours or theirs.
Status Tracker
VariableStartAfter Step 2After Step 3After Step 4
file.txt contentConflict markers presentOur version replaces conflictOur version stagedOur version committed
Key Moments - 2 Insights
Why does 'git checkout --ours' not immediately commit the change?
Because it only replaces the conflicted file content with our version locally; you must still stage (git add) and commit to finalize.
What happens if you forget to 'git add' after choosing ours or theirs?
The conflict remains unresolved and git will not allow the merge commit until you stage the resolved file, as shown in steps 2 and 3.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the file content after step 6?
ATheir version of file.txt
BOur version of file.txt
CConflict markers still present
DFile deleted
💡 Hint
Check the 'File Content Chosen' column at step 6 in the execution table.
At which step does the conflict become resolved when choosing 'ours'?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look for 'Conflict resolved' in the 'Conflict State' column for the 'ours' path.
If you skip 'git add' after choosing 'theirs', what happens?
AMerge completes successfully
BConflict remains unresolved
CGit automatically stages the file
DGit aborts the merge
💡 Hint
Refer to key moment about forgetting 'git add' and the execution table steps 6 and 7.
Concept Snapshot
git merge may cause conflicts.
Use 'git checkout --ours <file>' to keep your version.
Use 'git checkout --theirs <file>' to keep incoming version.
Then 'git add <file>' to stage resolved file.
Finally, 'git commit' to finish merge.
Without staging, merge cannot complete.
Full Transcript
When you merge branches in git, sometimes files conflict because both branches changed the same lines. Git stops and marks the conflict. You must pick which version to keep: your current branch's version ('ours') or the incoming branch's version ('theirs'). You do this by running 'git checkout --ours <file>' or 'git checkout --theirs <file>'. This replaces the conflicted file content locally. Then you stage the file with 'git add <file>' to tell git the conflict is resolved. Finally, you commit the merge with 'git commit'. If you skip staging, git will not let you finish the merge. This process helps you control which changes survive conflicts.