Git Rebase

Replay commits onto a new base for a linear, review-friendly history.

  • git rebase
  • interactive rebase
  • git pull rebase
  • rebase conflict
  • squash commits

Git Rebase

Replay commits onto a new base for a linear, review-friendly history.

Commands

CommandWhat it does
git rebase mainReplay current branch on top of main
git rebase -i HEAD~3Interactively reword, squash, or drop 3 commits
git rebase --continueResume after resolving conflicts
git rebase --abortCancel and return to the pre-rebase state
git pull --rebaseFetch and rebase instead of merging

Example

git switch feature/search
git rebase main
git rebase -i HEAD~2  # squash fixups

FAQ

Rebase or merge?

Rebase private feature branches for linear history; merge shared branches (main) to avoid rewriting public history.

Is rebasing pushed commits safe?

Only if no one else builds on them; otherwise it duplicates commits for collaborators.

Preguntas frecuentes

Rebase or merge?
Rebase private feature branches for linear history; merge shared branches (main) to avoid rewriting public history.
Is rebasing pushed commits safe?
Only if no one else builds on them; otherwise it duplicates commits for collaborators.

Git