Git Rebase Cheat Sheet

Advanced rebase commands, interactive workflows, conflict handling, and branch-transplant patterns.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Interactive Rebase Basics

Open, edit, and manage interactive rebase sessions.

Interactive rebase last 3 commits

Edit the last 3 commits.

bashANYgitrebaseinteractive
bash
git rebase -i HEAD~3
Notes

Opens the todo list so you can reorder, squash, edit, or drop commits.

Edit rebase todo during a rebase

Open the rebase todo list while a rebase is in progress.

bashANYgitrebaseinteractivetodo
bash
git rebase --edit-todo
Notes

Helpful when you need to change the sequence or actions after the rebase has already started.

Show current patch during rebase

Inspect the patch currently being replayed.

bashANYgitrebaseconflictpatch
bash
git rebase --show-current-patch
Notes

Useful when a rebase stops on a conflict and you want to see the exact patch Git is trying to apply.

Continue rebase after resolving conflicts

Resume the rebase once conflicts are fixed.

bashANYgitrebasecontinueconflicts
bash
git rebase --continue
Notes

Standard next step after resolving conflicts and staging the intended resolutions.

Abort a rebase

Cancel a rebase and return to the starting state.

bashANYgitrebaseabort
bash
git rebase --abort
Notes

Use this when the rebase becomes too messy or you want to restart with a different strategy.

Skip the current patch during rebase

Omit the commit currently being replayed.

bashANYgitrebaseskip
bash
git rebase --skip
Notes

Only use when you intentionally want to drop the stopped patch from the rebased history.

Interactive Rebase Actions

Common todo-list actions used in interactive rebase.

Keep commit as-is

Todo action to replay a commit normally.

textANYgitrebasetodopick
text
pick a1b2c3d Commit message
Notes

`pick` is the default action and applies the commit as a normal rebased commit.

Change commit message during rebase

Replay the commit but edit its message.

textANYgitrebasetodoreword
text
reword a1b2c3d Commit message
Notes

Use `reword` when the commit content is correct but the message needs cleanup.

Stop to amend a commit during rebase

Replay the commit and pause so you can modify it.

textANYgitrebasetodoedit
text
edit a1b2c3d Commit message
Notes

Use `edit` when you need to change the commit content, split the commit, or otherwise manipulate it mid-rebase.

Squash commit into previous commit

Combine two commits and merge their messages.

textANYgitrebasetodosquash
text
squash d4e5f6g Follow-up fix
Notes

`squash` merges the commit into the previous one and opens an editor to combine messages.

Fix up previous commit

Combine commit into previous commit and discard this commit message.

textANYgitrebasetodofixup
text
fixup d4e5f6g Follow-up fix
Notes

Ideal when the follow-up commit should disappear into the previous commit without preserving its message.

Drop a commit during rebase

Omit a commit from the rewritten history.

textANYgitrebasetododrop
text
drop badc0de Temporary experiment
Notes

Use `drop` carefully because it removes the commit from the resulting branch history.

Common Rebase Workflows

Typical advanced rebasing patterns.

Rebase current branch onto main

Replay your branch on top of the latest main.

bashANYgitrebasemainworkflow
bash
git rebase main
Notes

Keeps feature history linear by replaying it on top of another branch tip.

Fetch and rebase instead of merge

Update your current branch with a linear pull strategy.

bashANYgitpullrebaseworkflow
bash
git pull --rebase
Notes

Often preferred for keeping local history clean when syncing with a tracking branch.

Transplant a subset of commits

Move only part of a branch to a new base.

bashANYgitrebaseontoworkflow
bash
git rebase --onto new-base old-base topic
Notes

Classic advanced rebase pattern for moving a subset of commits that originally started after `old-base`.

Rewrite history from the root commit

Run interactive rebase from the start of the repository.

bashANYgitrebaseroothistory
bash
git rebase -i --root
Notes

Useful for cleaning very early history or splitting an initial commit in private repositories.

Rebase with autostash

Temporarily stash dirty worktree changes before rebasing.

bashANYgitrebaseautostashworkflow
bash
git rebase --autostash main
Notes

Helpful when your working tree is not clean but you still need to rebase.

Rebase preserving merges

Maintain merge structure while rebasing.

bashANYgitrebasemergeworkflow
bash
git rebase --rebase-merges main
Notes

A more advanced option when branch history contains meaningful merges that should not be flattened.

Rebase Conflicts and Recovery

Diagnose and recover from difficult rebase situations.

Check status during rebase

Inspect rebase state and unresolved files.

bashANYgitrebasestatusconflicts
bash
git status
Notes

Git status gives the clearest view of what remains to be resolved during a paused rebase.

Enable rerere globally

Reuse recorded conflict resolutions in future rebases and merges.

bashANYgitrebasererereconflicts
bash
git config --global rerere.enabled true
Notes

A strong quality-of-life improvement for repeated rebases or long-lived branches.

Take ours side for a conflicted file

Resolve one conflicted path using the current branch side.

bashANYgitrebaseconflictours
bash
git checkout --ours path/to/file && git add path/to/file
Notes

Useful in conflict resolution when you intentionally want your branch version of a path.

Take theirs side for a conflicted file

Resolve one conflicted path using the incoming side.

bashANYgitrebaseconflicttheirs
bash
git checkout --theirs path/to/file && git add path/to/file
Notes

Useful in conflict resolution when the rebased-on branch version should win for a path.

Find pre-rebase state in reflog

Locate the branch state before an unwanted rebase.

bashANYgitrebasereflogrecovery
bash
git reflog | head -20
Notes

Reflog is usually the fastest recovery path when a rebase result is not what you wanted.

Recommended next

No recommendations yet.