Algocraft / Git Commands / git merge

🔀

git merge

Combine two branches' histories — a fast-forward pointer move when possible, a two-parent merge commit when they've diverged

Fast-Forward Three-Way Merge --no-ff Merge Commit
Commit Graph Step 0 / 0
Working Directory → Staging → Repository
Terminal Transcript

Key Concepts

🎯 When to Use
  • Bringing a finished feature branch back into main
  • Combining two independently-developed lines of work
  • Keeping a full, honest record of when branches joined
⚖️ Fast-Forward vs 3-Way
  • FF: current branch has no new commits — Git just moves the pointer
  • 3-way: both sides added commits — Git creates a merge commit
  • --no-ff forces a merge commit even when FF is possible, to keep feature history visible
🎓 Pro Tips
  • A merge commit has two parents — that's how you spot one in git log
  • Conflicts happen when both sides changed the same lines — this demo auto-resolves for clarity
  • Prefer merge over rebase on branches other people have already pulled