0
0
Gitdevops~20 mins

Ours vs theirs in conflicts in Git - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Merge Conflict Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding 'ours' and 'theirs' in Git merge conflicts

When resolving a merge conflict in Git, what does the term 'ours' refer to?

AThe changes from the branch you are currently on (your working branch).
BThe changes from the branch you are merging into your current branch.
CThe changes from the remote repository's default branch.
DThe changes from the last commit before the merge started.
Attempts:
2 left
💡 Hint

Think about which branch you have checked out when you start the merge.

💻 Command Output
intermediate
1:30remaining
Output of choosing 'ours' during conflict resolution

You have a merge conflict in a file named app.js. You run the command git checkout --ours app.js followed by git add app.js. What will be the content of app.js after these commands?

AThe content of <code>app.js</code> from the branch you are merging in.
BThe content of <code>app.js</code> from your current branch before the merge.
CAn empty file with conflict markers still present.
DThe content of <code>app.js</code> from the last commit on the remote repository.
Attempts:
2 left
💡 Hint

'--ours' means to keep your current branch's version of the file.

🔀 Workflow
advanced
2:00remaining
Resolving conflicts preferring 'theirs' changes

You are merging a feature branch into your main branch and want to resolve all conflicts by accepting the changes from the feature branch (theirs). Which sequence of commands correctly achieves this for all conflicted files?

Agit merge feature; git checkout --theirs .; git add .; git commit -m 'Resolved conflicts using theirs'
Bgit merge feature; git checkout --ours .; git add .; git commit -m 'Resolved conflicts using theirs'
Cgit merge feature; git revert --theirs; git add .; git commit -m 'Resolved conflicts using theirs'
Dgit merge feature; git reset --hard; git commit -m 'Resolved conflicts using theirs'
Attempts:
2 left
💡 Hint

Remember that --theirs means the branch you are merging in.

Troubleshoot
advanced
1:30remaining
Error when using 'git checkout --theirs' on a non-conflicted file

You run git checkout --theirs README.md but get the error: error: pathspec 'README.md' did not match any files. What is the most likely cause?

AYou have uncommitted changes in README.md preventing checkout.
BYou are not inside a Git repository.
CThe file README.md is ignored by .gitignore.
DThe file README.md is not in conflict, so 'theirs' version does not exist.
Attempts:
2 left
💡 Hint

'--theirs' only works on files with merge conflicts.

Best Practice
expert
2:30remaining
Choosing between 'ours' and 'theirs' in a complex conflict scenario

During a complex merge conflict involving multiple files, you want to keep your current branch's changes for configuration files but accept incoming changes for source code files. Which approach best achieves this?

AAbort the merge and manually copy files from each branch outside Git, then commit.
BUse <code>git checkout --theirs</code> on all files, then manually revert config files after commit.
CUse <code>git checkout --ours</code> on config files and <code>git checkout --theirs</code> on source code files, then stage and commit.
DUse <code>git merge --strategy=ours</code> to keep all current branch changes.
Attempts:
2 left
💡 Hint

Selective checkout of 'ours' or 'theirs' per file allows fine control.