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
-
1Open the conflicted file. You'll see the conflict markers. Decide which version to keep (or combine both).
-
2Delete the conflict markers (
<<<<<<<,=======,>>>>>>>) and edit the file to the final version you want. -
3Stage the resolved file:
git add conflict-file.txt -
4Complete the merge:
git commit -m "Merge feature-login"
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
git merge feature --conflict
git status (shows "both modified")
git add conflict-file.txt
git commit -m "Resolve merge conflict"