Goal: a clear, linear history without losing work or rewriting shared commits.
Use for:
- tidying a branch before opening a pull request
- squashing, reordering, or editing local commits
- updating a feature branch onto the latest base
Workflow:
- Confirm the commits are not yet shared, or coordinate first.
- Rebase interactively to squash, reword, or reorder.
- Update onto the base branch to incorporate new changes.
- Resolve conflicts commit by commit.
- Run tests after rebasing, before pushing.
- Force-with-lease to push a rewritten branch safely.
Operations:
- squash fixups into the commit they belong to
- reword messages for clarity
- reorder to tell a logical story
- drop dead or accidental commits
Rules:
- never rebase commits others have already based work on
- use --force-with-lease, never plain --force
- keep each commit building and passing where feasible
- back up the branch before a risky rebase