Warm-up · from “Cherry-picking”
Does cherry-pick import all ancestors of a commit into the target branch's history?
Does cherry-pick import all ancestors of a commit into the target branch's history?
No notes: write what you remember, then check. Recalling before reading is what makes it stick.
The problem
Your feature branch diverged from main. You want a clean sequence of local commits on top of current main before review.
After this lesson you can
Explain replay and identity changes.
Perform a rebase.
Distinguish ordinary and interactive rebase.
Key terms
Full glossarySay what each term means, then open it to check.
Commit · from lesson 7
Object identifying a root tree, parent(s), metadata and message.
Tree · from lesson 6
Directory snapshot mapping names, modes and object IDs.
Ref · from lesson 3
Name identifying an object; branch refs usually identify commits.
Visual mental model
- Beforefeature C on A
- Afterfeature C′ on B
Build the mental model
In a simple linear case, git rebase main selects commits unique to the feature history and reapplies their changes on top of main, then moves the feature ref to the result. Git can skip equivalent patches or empty commits and may fast-forward in some cases. Ordinary rebase does not preserve merge topology by default; --rebase-merges is an advanced option.
A simplified model for building intuition. It does not read your sandbox; use the terminal for real behaviour.
Under the hood
Interactive rebase lets you reorder, reword, squash, fixup or drop commits in a selected range. Start from a clean working tree and create a backup ref before rewriting valuable history. If a conflict occurs, resolve and stage, then git rebase --continue; --abort returns to the pre-rebase state. During replay, ours is the upstream plus already replayed work, and theirs is the commit currently being replayed.
Common mistake · important nuance
Avoid rewriting published shared history without agreement. Rebase is not a literal move of existing commit objects.