Skip to main content
>_ supraj.dev
TOPIC GIT
Rebase vs Merge two ways to combine work
IN 10 SECONDS

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.

GOTCHA Never rebase commits that have been pushed to public repositories. Rebasing rewrites SHAs, causing merge conflicts for anyone else pulling history.
HOW REBASING REWRITES COMMITS
01 Work splits main branch moves forward with commits while you work on feature-a.
02 Rebase call runs git rebase main. Git shelves your feature commits temporarily.
03 Base swap git updates feature branch base pointer to point to current main head.
04 Re-apply applies feature commits sequentially on top. Commit SHAs are rewritten.
POKE IT YOURSELF
git rebase main — rebase current branch commits onto main branch
git rebase -i HEAD~3 — interactively squash or edit the last 3 commits