Cheatsheet: Rebase, deeper
Voice anchor
Section titled “Voice anchor”Git stores snapshots. Every other command is just navigating those snapshots.
Interactive rebase command reference
Section titled “Interactive rebase command reference”| Goal | Command |
|---|---|
| Interactive rebase of last N commits | git rebase -i HEAD~N |
| Interactive rebase onto main | git rebase -i main |
| Interactive rebase with autosquash | git rebase -i --autosquash main |
| Resume after conflict | git rebase --continue |
| Skip current commit during rebase | git rebase --skip |
| Abort the rebase | git rebase --abort |
| Edit a specific commit’s content | pick then edit in todo, then git commit --amend + git rebase --continue |
| Combine commits into one with new message | squash action |
| Combine commits into one discarding extra messages | fixup action |
| Drop a commit entirely | drop action |
| Reword a commit’s message | reword action |
| Run command after a commit during replay | exec action |
| Always autosquash by default | git config --global rebase.autosquash true |
Fixup workflow
Section titled “Fixup workflow”| Goal | Command |
|---|---|
| Make a fixup commit during work | git commit --fixup=<sha> |
| Make a squash commit during work | git commit --squash=<sha> |
| Autosquash everything at cleanup | git rebase -i --autosquash <base> |
Force-push and safety
Section titled “Force-push and safety”| Goal | Command |
|---|---|
| Safe force-push your branch | git push --force-with-lease |
| Force-push without check (dangerous) | git push --force |
| Branch protection on main | Repository setting on GitHub/GitLab/Bitbucket: turn on “no force-push” |
Recovery
Section titled “Recovery”| Situation | Move |
|---|---|
| Mid-rebase, give up | git rebase --abort |
| Completed rebase, want to undo | git reflog, find pre-rebase entry, git reset --hard HEAD@{N} |
| Lost branch (deleted by mistake) | Same reflog approach: find the last commit on the branch, recreate the branch from it |
| Wrong commit became HEAD | git reset --hard HEAD@{N} to the right one |
| Lost work after force-push | Find a teammate or local copy that still has the old commits; force-push back |
Interactive rebase cleanup drill: model walk-through
Section titled “Interactive rebase cleanup drill: model walk-through”After the cleanup, your git log --oneline should look something like:
new2 (HEAD -> main) add second linenew1 add first linestart initialThe 6 commits collapsed into 2 plus the initial. Messages clean. Each “add line” commit is a clean atomic change.
Fixup-and-autosquash drill: model walk-through
Section titled “Fixup-and-autosquash drill: model walk-through”After autosquash, your log should show:
abc4 (HEAD) add baz functionabc3 add bar functionabc2 add foo function <-- the fixup got folded in hereabc1 initialNo fixup! commits left in the history. The fixup change is part of the original “add foo function” commit. Clean.
Conflict-during-rebase drill: model walk-through
Section titled “Conflict-during-rebase drill: model walk-through”The conflict markers show both versions:
<<<<<<< HEADport=8443=======port=9090>>>>>>> abc1234... (your commit being replayed)By keeping port=8443 (main’s value) and git add port.conf + git rebase --continue, you’re saying “for THIS replayed commit, the resolution is to keep main’s value.” The rebase finishes with main’s value intact. The original feature-branch change to port=9090 is effectively dropped via the resolution.
If you wanted to keep port=9090 from the feature branch, you’d resolve to that value instead. The rebase is neutral; you decide the resolution.
Recovery drill: model walk-through
Section titled “Recovery drill: model walk-through”git reflog # shows last 90 days of HEAD moves# Output might look like:# abc4 HEAD@{0}: rebase finished: ...# abc3 HEAD@{1}: rebase: ...# def1 HEAD@{2}: commit: ...# (and so on)
git reset --hard HEAD@{4} # back to a pre-rebase stategit log --oneline # original commits restoredCommon mistakes and fixes
Section titled “Common mistakes and fixes”| Mistake | Fix |
|---|---|
| Rebased main accidentally | git reset --hard <pre-rebase-sha> from reflog; don’t push |
| Force-pushed wrong history to main | Find teammate with old history, force-push back, sync team |
| Lost a commit during interactive rebase | git reflog, find the commit’s SHA, git cherry-pick it back |
| Rebase ended up with wrong commit messages | Run git rebase -i again, use reword to fix |
| Stuck in endless conflicts | git rebase --abort, squash locally, try again with one big rebase instead of many small ones |
| Stuck mid-rebase with no idea what to do | git rebase --abort (this is always safe to run; restores pre-rebase state) |
What’s in Phase 4 (L13-L16)
Section titled “What’s in Phase 4 (L13-L16)”L13 (Worktrees and parallel agents) opens Phase 4. Worktrees let you have multiple working directories from a single clone. The substrate for parallel AI agents and complex multi-context human work. The first lesson without a v1 equivalent in most git curricula.
L14 (Multi-agent integration patterns) builds on L13: three patterns for integrating work from parallel agents, lead orchestration, semantic-conflict catching at integration.
L15 (AI-authored commits and PRs) covers co-authorship conventions, the “Generated with Claude Code” marker, what the human review changes when an AI authored the code, release notes including AI contributions.
L16 (The future of git in an AI world) closes the track speculatively-but-grounded.