Bird
Raised Fist0
Gitdevops~20 mins

Merge conflicts why they happen 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!
🧠 Conceptual
intermediate
2:00remaining
Why do merge conflicts occur in Git?

Imagine two friends editing the same paragraph in a shared document at the same time. What causes Git to show a merge conflict when combining changes?

ABecause the commit messages are identical in both branches.
BBecause Git lost the internet connection during the merge process.
CBecause one branch deleted the entire file while the other branch added new files.
DBecause both branches changed the same lines differently, so Git cannot decide which change to keep.
Attempts:
2 left
💡 Hint

Think about what happens when two people edit the same exact sentence differently.

💻 Command Output
intermediate
2:00remaining
What is the output when a merge conflict happens?

You run git merge feature but the branches have conflicting changes. What message does Git show?

Git
git merge feature
ANothing happens, the merge is silent.
B
Auto-merging file.txt
CONFLICT (content): Merge conflict in file.txt
Automatic merge failed; fix conflicts and then commit the result.
CError: branch 'feature' does not exist.
DMerge completed successfully with no conflicts.
Attempts:
2 left
💡 Hint

Look for keywords like 'CONFLICT' and 'Automatic merge failed'.

Troubleshoot
advanced
2:00remaining
How to identify conflicting files after a merge conflict?

After a merge conflict, which Git command lists the files that have conflicts needing resolution?

Agit status
Bgit branch
Cgit log
Dgit commit
Attempts:
2 left
💡 Hint

Think about which command shows the current state of your working directory and staged files.

🔀 Workflow
advanced
3:00remaining
What is the correct workflow to resolve a merge conflict?

After a merge conflict, what is the correct sequence of steps to fix and complete the merge?

A4,1,2,3
B1,4,2,3
C4,2,1,3
D2,1,4,3
Attempts:
2 left
💡 Hint

Remember you must start the merge, then fix conflicts, stage changes, and finally commit.

Best Practice
expert
2:30remaining
Why is it best to pull frequently to avoid merge conflicts?

Which reason best explains why regularly pulling changes from the main branch helps reduce merge conflicts?

ABecause Git locks files when you pull, preventing others from editing them.
BBecause pulling deletes your local changes automatically to avoid conflicts.
CBecause it keeps your branch updated with others' changes, reducing the chance of conflicting edits accumulating.
DBecause pulling merges all branches into one automatically without conflicts.
Attempts:
2 left
💡 Hint

Think about how staying updated helps avoid surprises when merging.

Practice

(1/5)
1. Why do merge conflicts happen in Git?
easy
A. Because Git lost the commit history
B. Because the same part of a file was changed differently in two branches
C. Because the repository is too large
D. Because the branch names are the same

Solution

  1. Step 1: Understand what causes merge conflicts

    Merge conflicts happen when Git tries to combine changes but finds different edits in the same part of a file from two branches.
  2. Step 2: Identify the correct cause

    Only when the same lines are changed differently does Git stop and ask for help, causing a conflict.
  3. Final Answer:

    Because the same part of a file was changed differently in two branches -> Option B
  4. Quick Check:

    Same file part changed differently = merge conflict [OK]
Hint: Conflicts happen when edits overlap in the same file area [OK]
Common Mistakes:
  • Thinking conflicts happen due to repo size
  • Believing branch names cause conflicts
  • Assuming commit history loss causes conflicts
2. Which Git command is used to start a merge that might cause conflicts?
easy
A. git push
B. git branch
C. git clone
D. git merge

Solution

  1. Step 1: Identify the command that combines branches

    The git merge command is used to combine changes from one branch into another.
  2. Step 2: Understand when conflicts occur

    Conflicts can happen during this merge if changes overlap, so git merge is the command that triggers this process.
  3. Final Answer:

    git merge -> Option D
  4. Quick Check:

    git merge starts merges that may conflict [OK]
Hint: Use git merge to combine branches and check for conflicts [OK]
Common Mistakes:
  • Confusing git branch with git merge
  • Using git clone to merge
  • Thinking git push merges branches
3. Given two branches, master and feature, both changed the same line in app.txt. What will happen when you run git merge feature on master?
medium
A. Git will automatically merge without any issues
B. Git will delete app.txt
C. Git will create a merge conflict in app.txt
D. Git will ignore changes from feature branch

Solution

  1. Step 1: Analyze the changes in both branches

    Both branches changed the same line in app.txt, so Git cannot decide which change to keep automatically.
  2. Step 2: Understand Git's behavior on conflicting changes

    Git will stop the merge and mark app.txt as conflicted, requiring manual resolution.
  3. Final Answer:

    Git will create a merge conflict in app.txt -> Option C
  4. Quick Check:

    Same line changed differently = conflict created [OK]
Hint: Same line changed in both branches causes conflict [OK]
Common Mistakes:
  • Assuming Git merges automatically always
  • Thinking Git deletes files on conflict
  • Believing Git ignores conflicting changes
4. You ran git merge feature and got a conflict. Which step should you take to fix it?
medium
A. Edit the file to choose which changes to keep, then commit
B. Rename the branch and try merging again
C. Run git push immediately
D. Delete the conflicting file and commit

Solution

  1. Step 1: Understand how to resolve merge conflicts

    When a conflict occurs, you must open the conflicting file and decide which changes to keep or combine.
  2. Step 2: Complete the merge after resolving conflicts

    After editing and saving the file, you add it and commit to finish the merge process.
  3. Final Answer:

    Edit the file to choose which changes to keep, then commit -> Option A
  4. Quick Check:

    Resolve conflicts by editing files, then commit [OK]
Hint: Fix conflicts by editing files before committing [OK]
Common Mistakes:
  • Deleting files instead of resolving conflicts
  • Pushing before resolving conflicts
  • Renaming branches to fix conflicts
5. Two developers edited different parts of the same file in separate branches. When merging, why might Git NOT report a conflict?
hard
A. Because changes are in different lines and Git can merge automatically
B. Because Git ignores changes in one branch
C. Because the file was deleted in one branch
D. Because the branches have the same name

Solution

  1. Step 1: Understand Git's merge behavior with non-overlapping changes

    If changes are made in different parts of a file, Git can combine them automatically without conflicts.
  2. Step 2: Recognize why no conflict occurs

    Since the edits do not overlap, Git merges both changes smoothly.
  3. Final Answer:

    Because changes are in different lines and Git can merge automatically -> Option A
  4. Quick Check:

    Non-overlapping changes merge without conflict [OK]
Hint: Different lines changed merge automatically [OK]
Common Mistakes:
  • Thinking Git ignores one branch's changes
  • Assuming file deletion causes no conflict
  • Believing branch names affect conflicts