Progress:
TIER 1 · MODULE 23· Basics

git rebase

History rewriter. Powerful. Don't rebase what you've already pushed.

🎯 What & why

Replay commits onto a different base. Result: a linear history where your commits appear to have been written on top of the new base. Powerful. Rewrites SHAs. Don't rebase what you've already pushed unless you and your team are on the same page.

🧠 Mental model

Rebase finds the commits unique to your branch (base..HEAD), saves them as patches, resets your branch to the new base, and re-applies the patches one by one. New commits, new SHAs. Conflicts can interrupt; resolve and git rebase --continue.

🛠️ Synopsis

git rebase [-i | --interactive] [<options>] [--exec <cmd>]
           [--onto <newbase>] [<upstream> [<branch>]]
git rebase (--continue | --skip | --abort | --quit | --edit-todo | --show-current-patch)

🎚️ Switches & options

FlagWhat it does
-i, --interactiveEdit the rebase plan: pick, reword, edit, squash, fixup, drop.
--onto <newbase>Replay commits onto <newbase> instead of <upstream>. Lets you rebase a slice.
--autosquashAuto-arrange fixup!/squash! commits.
--autostashStash dirty changes before rebasing.
--continueResume after resolving conflicts.
--abortRestore pre-rebase state.
--exec <cmd>Run <cmd> after each commit during rebase. Great for tests-per-commit.

💡 Use cases

🧪 Examples

Rebase current branch onto latest main.
$ git fetch origin
$ git rebase origin/main
Interactive: clean up the last 5 commits.
$ git rebase -i HEAD~5
Move a slice of commits from one base to another.
$ git rebase --onto target-branch old-base feature
Run tests after each commit.
$ git rebase --exec 'make test' origin/main

🎓 Recommendations

🪤 Common pitfalls

🔗 Related modules

📝 Quiz

Hit each option, then Check answers. Score is recorded; Next is always open.