Version Control & GitUpdated: 2026-11-07

The Essential Git Rebase & Conflict Resolution Cheat Sheet

Quick reference for interactive rebasing (git rebase -i), squash/fixup workflows, resolving conflict markers, and emergency reflog recovery.

Git rebasing is the primary technique professional developers use to maintain clean, linear commit histories before merging feature branches. Keep this cheat sheet bookmarked for interactive rebases, conflict marker resolution, and emergency undo commands.

Interactive Rebase Commands (git rebase -i)

Sub-commands used inside the interactive rebase TODO buffer.

CommandShort KeyAction Description
`pick``p`Keep the commit as-is and re-apply it onto the new base.
`squash``s`Meld the commit into the previous commit and edit combined commit message.
`fixup``f`Meld commit into previous commit, discarding this commit's message log.
`reword``r`Keep the commit's code changes but pause to edit the commit message.
`drop``d`Completely remove the commit and discard all its code changes.

Resolving Conflicts & Emergency Recovery

Terminal commands to resolve conflicts or undo botched rebases.

Conflict Resolution Lifecyclebash
# Start rebase onto updated main branch
git checkout feature-branch
git rebase main

# If conflict occurs, inspect conflicted files
git status

# After manually editing conflict markers, stage resolved files
git add path/to/resolved-file.ts

# Continue the rebase
git rebase --continue

# Emergency: completely abort and return to exact prior state
git rebase --abort

# Recovery: find lost commits using the reference log
git reflog
git reset --hard HEAD@{2}

Frequently Asked Questions

What is the Golden Rule of Git Rebasing?

Never rebase a branch that has been pushed to a shared public repository (like main or staging) that other developers are actively branching from.

Can git reflog recover commits deleted by git reset --hard?

Yes! Git retains unreachable commits in the reflog for typically 30 to 90 days before garbage collection runs.