WTF is Git Rebase (and Why It’s Both Magic and Chaos)
So you’ve been happily doing:
git pull
git merge
And then someone in your team says:
“Just rebase it.” …and you start questioning your life choices.
WTF Is Git Rebase, Really?
Definition (boring version):
git rebase
is a command that lets you rewrite the commit history by moving or combining commits onto a new base commit.
Definition (WTF version): Rebase is basically telling Git:
Yo, take my messy branch, pretend I started working from this new place, and make it look like I always had my sh*t together.
Why Even Bother?
Without rebase: Your history looks like:
main ---A---B---C
\
D---E (feature)
Then you merge:
main ---A---B---C------merge commit
\ /
D---E-----
Looks like spaghetti 🍝.
With rebase:
main ---A---B---C
\
D'---E'
(Notice the '
? Those are rebased commits. Same code, different timeline.)
The Actual WTF Command
Say you’re on feature
branch and want it updated with main
:
git checkout feature
git fetch origin
git rebase origin/main
Boom. Feature branch now looks like it was based on the latest main
all along.
Congratulations, you’re now a Git historian.
Common Rebase Moves
- Interactive Rebase:
git rebase -i HEAD~3
Lets you: ✅ squash commits ✅ rename commits ✅ feel like a time-traveling wizard
- Abort if you panic:
git rebase --abort
(You WILL need this.)
- Continue after fixing conflicts:
git add .
git rebase --continue
When conflicts hit you like a truck…
When to Use Rebase vs Merge
✅ Use rebase when:
- You want a clean history
- You’re working on your own feature branch
- You hate merge commits
❌ Don’t rebase shared branches (like main
), or you’ll rewrite history and summon demons in your team Slack.
Pros and Cons of Rebasing
✔ Pros:
- Cleaner history
- No merge commits
- Makes you feel pro
✖ Cons:
- Can cause conflicts
- Rewrite history → danger zone
- Makes newbies(me) cry
Interactive demo
web-app - Git Rebase Simulator
Current branch: feature
Repository Branches
Git Rebase Actions Guide
Use the commit as-is. This is the default action.
Use commit but edit the commit message.
Use commit but stop for amending.
Meld into previous commit and edit message.
Like squash but discard commit message.
Remove the commit entirely.
TL;DR WTF
git merge
= keep the messgit rebase
= rewrite history to look clean- Do it locally, don’t mess with shared branches
- Always have
--abort
and coffee ready ☕
🔥 Next WTF Episode:
WTF is
git cherry-pick
(and why it ruins friendships)