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
Interactive rebase last 3 commits
git rebase -i HEAD~3

# Edit the last 3 commits.

Edit rebase todo during a rebase
git rebase --edit-todo

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

Show current patch during rebase
git rebase --show-current-patch

# Inspect the patch currently being replayed.

Continue rebase after resolving conflicts
git rebase --continue

# Resume the rebase once conflicts are fixed.

Abort a rebase
git rebase --abort

# Cancel a rebase and return to the starting state.

Skip the current patch during rebase
git rebase --skip

# Omit the commit currently being replayed.

## Interactive Rebase Actions
Keep commit as-is
pick a1b2c3d Commit message

# Todo action to replay a commit normally.

Change commit message during rebase
reword a1b2c3d Commit message

# Replay the commit but edit its message.

Stop to amend a commit during rebase
edit a1b2c3d Commit message

# Replay the commit and pause so you can modify it.

Squash commit into previous commit
squash d4e5f6g Follow-up fix

# Combine two commits and merge their messages.

Fix up previous commit
fixup d4e5f6g Follow-up fix

# Combine commit into previous commit and discard this commit message.

Drop a commit during rebase
drop badc0de Temporary experiment

# Omit a commit from the rewritten history.

## Common Rebase Workflows
Rebase current branch onto main
git rebase main

# Replay your branch on top of the latest main.

Fetch and rebase instead of merge
git pull --rebase

# Update your current branch with a linear pull strategy.

Transplant a subset of commits
git rebase --onto new-base old-base topic

# Move only part of a branch to a new base.

Rewrite history from the root commit
git rebase -i --root

# Run interactive rebase from the start of the repository.

Rebase with autostash
git rebase --autostash main

# Temporarily stash dirty worktree changes before rebasing.

Rebase preserving merges
git rebase --rebase-merges main

# Maintain merge structure while rebasing.

## Rebase Conflicts and Recovery
Check status during rebase
git status

# Inspect rebase state and unresolved files.

Enable rerere globally
git config --global rerere.enabled true

# Reuse recorded conflict resolutions in future rebases and merges.

Take ours side for a conflicted file
git checkout --ours path/to/file && git add path/to/file

# Resolve one conflicted path using the current branch side.

Take theirs side for a conflicted file
git checkout --theirs path/to/file && git add path/to/file

# Resolve one conflicted path using the incoming side.

Find pre-rebase state in reflog
git reflog | head -20

# Locate the branch state before an unwanted rebase.

Recommended next

No recommendations yet.