Vasu Patel logoVasu Patel
← Git Mastery
All chapters in this track
  1. 011. The Mental Model
  2. 022. Essential Setup
  3. 033. Core Daily Workflow
  4. 044. Branching
  5. 055. Merging & Conflict Resolution
  6. 066. Rebasing
  7. 077. Remote Repositories
  8. 088. Stashing
  9. 099. Undoing Things
  10. 1010. Tagging & Versioning
  11. 1111. Cherry-Pick
  12. 1212. Git Bisect & Blame
  13. 1313. Git Hooks
  14. 1414. Submodules
  15. 1515. Team Workflows
  16. 1616. Power Commands & Aliases
  17. 1717. Reflog: The Safety Net
  18. 1818. Practice Tasks
  19. 19Quick Reference Cheatsheet

Chapter 5 of 19

5. Merging & Conflict Resolution

Fast-forward merge (no divergence)

git switch main
git merge feature/login      # if main hasn't moved, HEAD just advances

3-way merge (branches diverged)

git merge feature/login      # creates a merge commit
git merge --no-ff feature/login   # always create merge commit (preserves history)
git merge --squash feature/login  # squash all branch commits into one staged change

Resolving conflicts

When Git can't auto-merge, you see conflict markers:

<<<<<<< HEAD
    return user.isAdmin;
=======
    return user.role === 'admin';
>>>>>>> feature/role-check

Steps to resolve:

# 1. See which files conflict
git status

# 2. Edit each conflicted file — remove markers, keep the right code

# 3. Mark resolved
git add path/to/file.txt

# 4. Complete the merge
git commit

# OR abort entirely
git merge --abort

Merge tool:

git mergetool          # opens configured visual diff tool
git config --global merge.tool vscode

Merge vs Rebase — when to use each

SituationPrefer
Shared/public branchMerge (preserves history)
Local cleanup before PRRebase (linear history)
Main ← featureMerge
feature ← updated mainRebase (keep feature up-to-date)