Bird
Raised Fist0
Gitdevops~10 mins

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

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
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.

Practice

(1/5)
1. In a Git merge conflict, what does ours refer to?
easy
A. A backup copy of the file before the merge
B. The version of the file in the branch you are merging
C. The common ancestor version of the file
D. The version of the file in your current branch

Solution

  1. Step 1: Understand the meaning of 'ours' in Git conflicts

    'Ours' means the version of the file in your current branch where you started the merge.
  2. Step 2: Differentiate from 'theirs'

    'Theirs' refers to the version from the branch you are merging into your current branch.
  3. Final Answer:

    The version of the file in your current branch -> Option D
  4. Quick Check:

    Ours = current branch version [OK]
Hint: Ours = your branch, theirs = merging branch [OK]
Common Mistakes:
  • Confusing 'ours' with 'theirs'
  • Thinking 'ours' means the common ancestor
  • Assuming 'ours' is a backup copy
2. Which Git command correctly chooses the 'theirs' version of a conflicted file named app.js?
easy
A. git checkout --ours app.js
B. git checkout --theirs app.js
C. git reset --theirs app.js
D. git merge --theirs app.js

Solution

  1. Step 1: Identify the correct command to pick 'theirs'

    The command to choose the 'theirs' version during conflict is git checkout --theirs <file>.
  2. Step 2: Verify the file name usage

    Using app.js after the command specifies the file to resolve.
  3. Final Answer:

    git checkout --theirs app.js -> Option B
  4. Quick Check:

    Use 'git checkout --theirs' to pick theirs [OK]
Hint: Use 'git checkout --theirs <file>' to pick theirs version [OK]
Common Mistakes:
  • Using 'git reset' instead of 'git checkout'
  • Confusing '--ours' with '--theirs'
  • Trying 'git merge --theirs' which is invalid
3. After a merge conflict on index.html, you run:
git checkout --ours index.html
What will be the content of index.html after this command?
medium
A. The version from your current branch before the merge
B. The version from the branch you are merging
C. The common ancestor version
D. An empty file

Solution

  1. Step 1: Understand what 'git checkout --ours' does in conflict

    This command replaces the conflicted file with the version from your current branch before the merge.
  2. Step 2: Confirm the file content after the command

    After running it, index.html will have your branch's original content, ignoring the other branch's changes.
  3. Final Answer:

    The version from your current branch before the merge -> Option A
  4. Quick Check:

    'git checkout --ours' = current branch content [OK]
Hint: Checkout --ours picks your branch's file version [OK]
Common Mistakes:
  • Thinking it picks the other branch's version
  • Assuming it resets to common ancestor
  • Expecting it to merge both versions automatically
4. You tried to resolve a conflict by running git checkout --theirs main.js but the file did not update. What is the likely cause?
medium
A. You need to commit before checking out
B. You used the wrong file name
C. You are not in a conflicted merge state
D. The command only works after resolving conflicts manually

Solution

  1. Step 1: Check the merge state requirement

    The git checkout --theirs command only works when Git detects a conflict during a merge.
  2. Step 2: Understand why the file didn't update

    If you are not in a conflicted state, Git has no 'theirs' version to apply, so the file stays unchanged.
  3. Final Answer:

    You are not in a conflicted merge state -> Option C
  4. Quick Check:

    'git checkout --theirs' needs conflict state [OK]
Hint: Use 'git status' to confirm conflict before checkout --theirs [OK]
Common Mistakes:
  • Trying to use --theirs outside a merge conflict
  • Assuming checkout updates file without conflict
  • Not verifying current branch or file name
5. During a complex merge conflict involving multiple files, you want to keep your current branch's version for config.yaml but accept the other branch's version for README.md. Which sequence of commands correctly resolves this?
hard
A. git checkout --ours config.yaml && git checkout --theirs README.md && git add config.yaml README.md
B. git checkout --theirs config.yaml && git checkout --ours README.md && git add config.yaml README.md
C. git reset --ours config.yaml && git reset --theirs README.md && git commit -m 'Resolve conflicts'
D. git merge --ours config.yaml README.md

Solution

  1. Step 1: Use correct commands to pick versions per file

    To keep your branch's version for config.yaml, use git checkout --ours config.yaml. To accept the other branch's version for README.md, use git checkout --theirs README.md.
  2. Step 2: Stage the resolved files

    After choosing versions, add both files to the staging area with git add config.yaml README.md to mark conflicts resolved.
  3. Final Answer:

    git checkout --ours config.yaml && git checkout --theirs README.md && git add config.yaml README.md -> Option A
  4. Quick Check:

    Use checkout --ours/theirs per file, then git add [OK]
Hint: Pick versions per file with checkout, then git add to resolve [OK]
Common Mistakes:
  • Mixing up --ours and --theirs for files
  • Forgetting to git add after checkout
  • Using git reset or git merge incorrectly