Git rebasing safely
Rebase replays commits onto a new base and rewrites their identities, producing a linear history.
How it works
On a local feature branch, fetch the latest main and rebase your unpublished commits onto it, resolving each conflict before continuing; if the result is not what you intended, abort the operation, and coordinate before rewriting any history that another developer has already based work on.
git fetch origin
git rebase origin/main
# After resolving a conflict:
git add path/to/resolved-file
git rebase --continue
# To return to the state before this rebase:
git rebase --abortRead the documentationCommon misconception
Rebase does more than move a pointer: replayed commits receive new hashes.
Quick practice
1. What does rebase rewrite?
Commit history.
2. When is it safest?
On unpublished commits.
3. How do you cancel it?
git rebase --abort