Skip to content

Cheatsheet: Rebase, deeper

Git stores snapshots. Every other command is just navigating those snapshots.

GoalCommand
Interactive rebase of last N commitsgit rebase -i HEAD~N
Interactive rebase onto maingit rebase -i main
Interactive rebase with autosquashgit rebase -i --autosquash main
Resume after conflictgit rebase --continue
Skip current commit during rebasegit rebase --skip
Abort the rebasegit rebase --abort
Edit a specific commit’s contentpick then edit in todo, then git commit --amend + git rebase --continue
Combine commits into one with new messagesquash action
Combine commits into one discarding extra messagesfixup action
Drop a commit entirelydrop action
Reword a commit’s messagereword action
Run command after a commit during replayexec action
Always autosquash by defaultgit config --global rebase.autosquash true
GoalCommand
Make a fixup commit during workgit commit --fixup=<sha>
Make a squash commit during workgit commit --squash=<sha>
Autosquash everything at cleanupgit rebase -i --autosquash <base>
GoalCommand
Safe force-push your branchgit push --force-with-lease
Force-push without check (dangerous)git push --force
Branch protection on mainRepository setting on GitHub/GitLab/Bitbucket: turn on “no force-push”
SituationMove
Mid-rebase, give upgit rebase --abort
Completed rebase, want to undogit 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 HEADgit reset --hard HEAD@{N} to the right one
Lost work after force-pushFind 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 line
new1 add first line
start initial

The 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 function
abc3 add bar function
abc2 add foo function <-- the fixup got folded in here
abc1 initial

No 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:

<<<<<<< HEAD
port=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.

Terminal window
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 state
git log --oneline # original commits restored
MistakeFix
Rebased main accidentallygit reset --hard <pre-rebase-sha> from reflog; don’t push
Force-pushed wrong history to mainFind teammate with old history, force-push back, sync team
Lost a commit during interactive rebasegit reflog, find the commit’s SHA, git cherry-pick it back
Rebase ended up with wrong commit messagesRun git rebase -i again, use reword to fix
Stuck in endless conflictsgit rebase --abort, squash locally, try again with one big rebase instead of many small ones
Stuck mid-rebase with no idea what to dogit rebase --abort (this is always safe to run; restores pre-rebase state)

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.