Rebasing and history
Replay commits on a fresh base and tidy a branch before review.
What you will be able to do
- Rebase a feature onto main
- Squash and reword with interactive rebase
- Force-push safely with a lease
Rebase replays your commits on top of another base, producing a linear history. It rewrites commit IDs, so only rebase branches that are yours and not shared.
git switch feature/pricing
git fetch origin
git rebase origin/main
git rebase -i HEAD~3
# squash, reword or reorder in the editor
git rebase --abort
git push --force-with-lease- rebase keeps history linear and reviews focused.
- Interactive rebase edits the last N commits before a pull request.
- Force-with-lease refuses to overwrite someone else's new commits.
- Never rebase main or any branch other people build on.
Your turn
MediumRebase onto main
Update the origin remote, then replay feature/pricing on top of origin/main.
BASH · starter
# your commands hereCheck your understanding before moving on.
Knowledge checkQuestion 1
What does interactive rebase let you do?
Select an answer to continue
Study tools
Make it yours.
Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.
Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign inFinished reading?
Lock in what you just learned.
0%
Mark this lesson complete to save your place and move one step closer to the certificate.