Rebasing in Git

From the Git cheat sheet · Branching · verified Jul 2026

Rebasing

Replay commits on top of another base for a linear history

bash
# Rebase current branch onto another
git rebase <branch>
git rebase main

# Interactive rebase (rewrite, reorder, squash)
git rebase -i HEAD~3

# Inside the interactive editor:
# pick    = keep commit
# reword  = change message
# edit    = stop to amend
# squash  = combine with previous (keep both messages)
# fixup   = combine with previous (drop this message)
# drop    = remove commit

# During a rebase
git rebase --continue   # After resolving conflicts
git rebase --skip       # Skip the current commit
git rebase --abort      # Cancel and reset
⚠️ Never rebase commits that are already pushed to a shared branch
💡 Rebase rewrites history; merge preserves it
✅ Use rebase locally to clean up before opening a PR
🔧 If you mess up, reflog has your back

Continue with Git

Save the full cheat sheet or work through every related task.

More Git tasks

Back to the full Git cheat sheet