Module 06 of 10 · merge · conflicts

Merging & Conflicts

Merging Branches

When your feature is ready, you bring it back into main with git merge. Always merge into the branch you want to update — so switch to main first:

git switch main
git merge feature-login

Fast-Forward vs Merge Commits

If main hasn't changed since you branched off, git does a fast-forward — it simply moves the main pointer forward. No merge commit is created.

If both branches have new commits, git creates a merge commit — a special commit with two parents that joins the histories together.

What is a Merge Conflict?

A conflict happens when both branches changed the same lines in the same file. Git can't automatically decide which version to keep, so it pauses and asks you to resolve it manually.

A conflicted file looks like this:

<<<<<<< HEAD
This is my version on main
=======
This is the feature branch version
>>>>>>> feature-login

Resolving a Conflict — Step by Step

  1. 1
    Open the conflicted file. You'll see the conflict markers. Decide which version to keep (or combine both).
  2. 2
    Delete the conflict markers (<<<<<<<, =======, >>>>>>>) and edit the file to the final version you want.
  3. 3
    Stage the resolved file: git add conflict-file.txt
  4. 4
    Complete the merge: git commit -m "Merge feature-login"
Never panic during a conflict. Git has not lost any work. Both versions exist inside those markers. You have full control. If you want to abort entirely: git merge --abort.

Challenge: Trigger and Resolve a Conflict

In this module the simulator will trigger a conflict for you. Type git merge feature --conflict to create one, then resolve it.

Your Challenges

Trigger a conflict: git merge feature --conflict
Check the status: git status (shows "both modified")
Resolve by staging the file: git add conflict-file.txt
Complete the merge: git commit -m "Resolve merge conflict"
Module 6 complete! Merge conflicts look scary but you now know exactly how to handle them. Most conflicts are easy to fix once you know the pattern.
student@git-mastery: ~/my-project (main)