10 / 57 · 17 Git & Version Control · Rebase vs Merge← prev⊞ allnext →☰ Read as one page
2.2Merge
A merge creates a new "merge commit" that combines the histories of two branches. The full branch history is preserved in the graph.
git checkout main
git merge feature/login-tests
# Creates a merge commit; feature branch history visible in graph
What the history looks like after merge:
main: A --- B --- C --- M (merge commit)
/ /
feature: D --- E --/
Both the main branch commits (A, B, C) and the feature branch commits (D, E) are visible. The merge commit (M) marks where integration happened.
Advantages of Merge
- Preserves history: You can see exactly when a feature branch was created and merged
- Safe for shared branches: Never rewrites existing commits
- Easy to revert: Revert the merge commit to undo an entire feature
Disadvantages of Merge
- Cluttered history: Many merge commits can make the log hard to read
- Noisy diffs: Merge commits can make
git log --onelineharder to scan