Bird
Raised Fist0
Gitdevops~3 mins

Why Resolving merge conflicts in Git? - Purpose & Use Cases

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
The Big Idea

What if you could fix messy teamwork without losing any work or wasting hours?

The Scenario

Imagine you and your friend are writing a story together, but you both edit the same sentence differently at the same time. When you try to put your versions together, the story gets messy and confusing.

The Problem

Trying to fix these mixed-up changes by hand is slow and frustrating. You might miss important parts or accidentally erase your friend's work. It's easy to get confused and make mistakes.

The Solution

Resolving merge conflicts with Git helps you see exactly where the changes clash. It guides you to choose or combine the best parts, making teamwork smooth and safe.

Before vs After
Before
Copy files from friend, overwrite your changes, lose work
After
git merge branch-name
# then edit conflict markers to fix
What It Enables

You can confidently combine work from many people without losing or breaking anything.

Real Life Example

A team working on a website updates the same page. Git shows conflicts clearly so they fix them quickly and keep the site running smoothly.

Key Takeaways

Manual merging is confusing and error-prone.

Git highlights conflicts to help fix them carefully.

Resolving conflicts keeps teamwork efficient and safe.

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