GIT / A CONCEPT NOTE
Rebase vs Merge
two ways to combine work
Overview · mechanism
pitfall · examples
01 / THE SHORT VERSION
The idea in a few sentences.
Merging keeps history unchanged by creating a new merge commit. Rebasing rewrites history by moving your commits onto the tip of the target branch, producing a flat linear timeline.
02 / FOLLOW THE MECHANISM
How rebasing rewrites commits
Work splits
main branch moves forward with commits while you work on feature-a.
Rebase call
runs git rebase main. Git shelves your feature commits temporarily.
Base swap
git updates feature branch base pointer to point to current main head.
Re-apply
applies feature commits sequentially on top. Commit SHAs are rewritten.
04 / COMMAND NOTES
Read the command, then the result.
Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.
rebase current branch commits onto main branch
git rebase maininteractively squash or edit the last 3 commits
git rebase -i HEAD~305 / CHECK YOURSELF
Could you explain Rebase vs Merge to a teammate?
Try it out loud in two sentences: what it is, and the one detail that changes the picture. If you stall, the gap is the part to reread.
Up next in Git & collaborationThe Staging Areawhy git has three states