Rebasing
Rebase moves or replays commits onto a new base. It can create a cleaner, linear-looking history, but it rewrites commit identities because the replayed commits are new commits.
A common workflow is rebasing a feature branch onto the latest main before opening a pull request.
Rebase Rewrites History
Do not casually rebase commits that other developers have already based work on. Shared history rewriting can force collaborators to reconcile divergent commit identities.
Rebase a Feature Branch
git switch feature/login
git fetch origin
git rebase origin/main💡 Git temporarily removes the feature commits, updates the base to
origin/main, and replays those feature commits on top of it.Key Takeaways
- Rebase creates new commit identities for replayed commits.
- Rebase can produce a linear history.
- Avoid rewriting public history unless the team explicitly agrees.
Knowledge Check
Why does rebasing change commit hashes?