Git Rebase

Rewrite commit history by replaying commits on top of another base. Cleaner history but requires caution.

On this page

What is rebase?

git rebase moves a sequence of commits to a new base commit.

Basic rebase

git checkout feature-branch
git rebase main

Interactive rebase

git rebase -i HEAD~3

Why use rebase?

  • Create linear history
  • Clean up commits before merging

Rebase vs Merge

  • Merge preserves history graph
  • Rebase rewrites history

Golden rule

Never rebase public branches.