Summary: Rebase, deeper
The one-sentence definition
Section titled “The one-sentence definition”Interactive rebase replays a sequence of commits and lets you edit, combine, drop, or reorder them along the way, producing a new clean history in place of the original messy one.
The interactive rebase flow
Section titled “The interactive rebase flow”git rebase -i HEAD~N # interactive rebase of last N commits# editor opens with todo list (oldest first)# edit actions, save, close# git replays each commit per the actions# resolve conflicts if they happen (--continue, --skip, --abort)The action keywords
Section titled “The action keywords”- pick: replay as-is (default)
- reword: replay, edit the message
- squash: combine into previous, edit combined message
- fixup: combine into previous, discard this message
- drop: delete the commit
- edit: pause after replay so you can amend content
- exec: run a shell command (e.g. tests) at this step
- break: pause for any reason
The proactive fixup-and-autosquash flow
Section titled “The proactive fixup-and-autosquash flow”git commit --fixup=<sha> # creates "fixup! <original-message>"# ... continue work ...git rebase -i --autosquash main # pre-arranges fixup commits at cleanupThe hard rule
Section titled “The hard rule”Don’t rebase published commits.
If you’ve pushed a commit to a shared branch and someone may have pulled it, do not rewrite it. Force-pushing rewritten history to main or any shared branch causes hours of recovery work and risks losing teammates’ commits.
Defenses:
- Branch protection on main forbids force-push entirely (platform setting; turn it on)
git push --force-with-leaseinstead of--forceon your own feature branches: checks that remote hasn’t advanced before overwriting- Triple-check your branch before any force-push
Recovery toolkit
Section titled “Recovery toolkit”| Situation | Move |
|---|---|
| Mid-rebase, want to give up | git rebase --abort |
| Already finished, want to undo | git reflog, then git reset --hard HEAD@{N} |
| Force-pushed wrong history to shared branch | Find someone with old history locally, force-push back, teammates reset |
| Stuck in a conflict storm | --abort, squash locally first (fewer conflicts), try again |
Rebase vs merge (one-line summary)
Section titled “Rebase vs merge (one-line summary)”Rebase when: local cleanup, linear history convention, integrating into a branch nobody else pulls from.
Merge when: branch is published and others pulled, want to preserve parallel-development story, long-lived release branches with audit-trail value.
Voice anchor
Section titled “Voice anchor”Git stores snapshots. Every other command is just navigating those snapshots.
Rebase replays snapshots onto a new base, creating new snapshots. Interactive rebase lets you decide which to keep, combine, or drop. The reflog records every HEAD state for 90 days.
What you carry into Phase 4
Section titled “What you carry into Phase 4”Phase 4 (L13-L16) crosses into multi-agent territory: worktrees (L13), integration patterns for parallel agents (L14), AI-authored commits and PRs (L15), and the future of git in an AI-collaborative world (L16).