DEV Community

Namit Jain
Namit Jain

Posted on

WTF is Git Rebase (and Why It’s Both Magic and Chaos)

So you’ve been happily doing:

git pull
git merge
Enter fullscreen mode Exit fullscreen mode


`

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:

bash
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:

bash
git rebase -i HEAD~3

Lets you:
✅ squash commits
✅ rename commits
✅ feel like a time-traveling wizard

  • Abort if you panic:

bash
git rebase --abort

(You WILL need this.)

  • Continue after fixing conflicts:

bash
git add .
git rebase --continue


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

Visit https://www.namitjain.com/blog/git-rebase for interactive demo


TL;DR WTF

  • git merge = keep the mess
  • git 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)

Top comments (1)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.