Bird
Raised Fist0
Gitdevops~20 mins

Resolving merge conflicts in Git - Practice Problems & Coding Challenges

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
Challenge - 5 Problems
🎖️
Merge Conflict Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output after a failed merge due to conflicts?
You run git merge feature-branch but there are conflicts. What message does Git show?
A
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
BMerge made by the 'recursive' strategy.
CAlready up to date.
Dfatal: Not a git repository (or any of the parent directories): .git
Attempts:
2 left
💡 Hint
Think about what Git says when it cannot automatically merge files.
🔀 Workflow
intermediate
2:00remaining
Correct sequence to resolve a merge conflict
Which sequence of commands correctly resolves a merge conflict and completes the merge?
A3,2,1,4
B2,1,3,4
C1,3,2,4
D1,2,3,4
Attempts:
2 left
💡 Hint
Start by checking status, then fix files, stage them, and commit.
Troubleshoot
advanced
2:00remaining
Why does 'git commit' fail after resolving conflicts?
You resolved all conflicts and staged the files, but git commit still fails with the message: error: Committing is not possible because you have unmerged files. What is the most likely cause?
AYour repository is corrupted and needs to be recloned.
BYou need to run <code>git merge --continue</code> instead of <code>git commit</code>.
CYou forgot to stage all conflicted files after resolving conflicts.
DYou must delete the conflicted files before committing.
Attempts:
2 left
💡 Hint
Think about what Git requires before committing a merge.
🧠 Conceptual
advanced
2:00remaining
Understanding conflict markers in files
What do the conflict markers <<<<<<<, =======, and >>>>>>> in a file indicate?
AThey mark the conflicting sections from the current branch and the branch being merged.
BThey are comments added by Git to explain the merge process.
CThey indicate lines that were deleted during the merge.
DThey are placeholders for unresolved binary files.
Attempts:
2 left
💡 Hint
Think about how Git shows differences inside a conflicted file.
Best Practice
expert
2:00remaining
Best practice to avoid complex merge conflicts
Which practice helps reduce the chance of complex merge conflicts in a team working on the same codebase?
AAvoid committing changes until your feature is fully complete.
BFrequently pull and merge changes from the main branch into your feature branch.
CUse force push to overwrite remote branches when conflicts occur.
DWork on large features in a single long-lived branch without syncing.
Attempts:
2 left
💡 Hint
Think about keeping your branch up to date with others.

Practice

(1/5)
1. What does a merge conflict in Git mean?
easy
A. Git found changes in the same file that it cannot combine automatically.
B. Git has successfully merged all changes without any issues.
C. Git deleted a file during the merge process.
D. Git created a new branch automatically.

Solution

  1. Step 1: Understand merge conflict meaning

    A merge conflict happens when Git sees changes in the same part of a file from different branches and cannot decide which to keep.
  2. Step 2: Identify what Git does in this case

    Git stops the merge and marks the conflict in the file for you to fix manually.
  3. Final Answer:

    Git found changes in the same file that it cannot combine automatically. -> Option A
  4. Quick Check:

    Merge conflict = conflicting changes in same file [OK]
Hint: Merge conflict means manual fix needed for overlapping changes [OK]
Common Mistakes:
  • Thinking Git merges all changes automatically
  • Confusing conflict with branch creation
  • Assuming files are deleted automatically
2. Which Git command is used to mark a conflict as resolved after editing the file?
easy
A. git add <file>
B. git commit -m 'resolve conflict'
C. git merge --continue
D. git checkout --conflict

Solution

  1. Step 1: Identify how to tell Git conflict is fixed

    After editing the conflicted file, you must stage it to tell Git the conflict is resolved.
  2. Step 2: Choose the correct command to stage files

    The command to stage files is git add <file>.
  3. Final Answer:

    git add <file> -> Option A
  4. Quick Check:

    Stage resolved file with git add [OK]
Hint: Use git add to mark conflict resolved before commit [OK]
Common Mistakes:
  • Trying to commit before staging resolved files
  • Using git merge --continue without staging
  • Using invalid commands like git checkout --conflict
3. Given this conflict marker in a file after a merge:
<<<<<<< HEAD
Line A
=======
Line B
>>>>>>> feature-branch
What will the file content be after you keep only the changes from the feature-branch and stage the file?
medium
A. Line A
B. Line B
C. <<<<<<< HEAD Line A ======= Line B >>>>>>> feature-branch
D. Line A Line B

Solution

  1. Step 1: Understand conflict markers

    The lines between <<<<<<< HEAD and ======= are from current branch; lines between ======= and >>>>>>> feature-branch are from the other branch.
  2. Step 2: Keep only feature-branch changes

    To keep only feature-branch changes, remove the markers and the HEAD section, leaving just 'Line B'.
  3. Final Answer:

    Line B -> Option B
  4. Quick Check:

    Keep feature-branch changes = Line B [OK]
Hint: Remove conflict markers, keep desired lines, then git add [OK]
Common Mistakes:
  • Leaving conflict markers in file
  • Keeping both changes without cleaning markers
  • Confusing which side is which branch
4. You tried to merge a branch but Git reports conflicts. You edited the files but forgot to stage them before committing. What happens if you run git commit now?
medium
A. Git commits the merge with unresolved conflicts included.
B. Git automatically stages and commits the resolved files.
C. Git refuses to commit and shows an error about unmerged paths.
D. Git aborts the merge and resets to previous state.

Solution

  1. Step 1: Understand commit behavior during merge conflicts

    Git requires you to stage resolved files before committing a merge. If files are not staged, Git sees conflicts as unresolved.
  2. Step 2: What happens when committing without staging

    Git will refuse to commit and show an error about unmerged paths, preventing incomplete merges.
  3. Final Answer:

    Git refuses to commit and shows an error about unmerged paths. -> Option C
  4. Quick Check:

    Commit without staging resolved files = error [OK]
Hint: Always git add resolved files before git commit [OK]
Common Mistakes:
  • Assuming git commit auto-stages files
  • Thinking Git commits partial merges
  • Expecting merge to abort automatically
5. You have a file with multiple merge conflicts from two branches. You want to keep all changes from both branches but Git shows conflicts. What is the best way to resolve this?
hard
A. Run git reset --hard to discard all changes and merge again.
B. Use git merge --abort to cancel the merge and try again.
C. Delete the file and create a new one with combined content.
D. Manually edit the file to combine both changes, remove conflict markers, then stage and commit.

Solution

  1. Step 1: Understand the goal to keep all changes

    Since you want to keep both branches' changes, you must manually combine them in the file.
  2. Step 2: How to resolve conflicts properly

    Edit the file to merge both changes, remove conflict markers, then stage with git add and commit the merge.
  3. Final Answer:

    Manually edit the file to combine both changes, remove conflict markers, then stage and commit. -> Option D
  4. Quick Check:

    Manual merge + stage + commit = keep all changes [OK]
Hint: Edit conflicts to combine changes, then git add and commit [OK]
Common Mistakes:
  • Aborting merge instead of resolving
  • Deleting files losing changes
  • Resetting hard losing all work