← Back to Mission Control

Timeline Rewriting

8 min read

Git Rebase

Mission Phase 24 • Difficulty: Advanced

Rewriting History

Rebase rewrites commit history to create a cleaner, more linear timeline. It's one of Git's most powerful tools—and one that requires caution.

Basic Rebase

# From your feature branch
git rebase main

This replays your commits on top of main, as if you had started your feature from the latest main commit.

Rebase vs Merge

Interactive Rebase

git rebase -i HEAD~3

Opens an editor to modify your last three commits. Available actions:

Squashing Commits

Combine several small commits into one meaningful one:

git rebase -i HEAD~3

Then change the plan to:

pick abc123 Add sensor calibration
squash def456 Fix typo
squash ghi789 Fix another typo

Resolving Rebase Conflicts

  1. Fix the conflicts in the affected files
  2. Stage the resolved files with git add
  3. Continue with git rebase --continue

Aborting a Rebase

git rebase --abort

Returns your branch to its state before the rebase began.

The Golden Rule

Never Rebase Public Commits

Don't rebase commits that have been pushed to shared branches. Doing so rewrites history that others depend on and causes chaos across the crew.

Rebase is safe for:

  • Local commits you haven't pushed yet
  • Personal feature branches
  • Cleaning up your history before opening a pull request

When to Use Rebase

When to Use Merge

Handy Rebase Options

git rebase --onto main old-base feature   # Replay onto a different base
git rebase --autostash main               # Stash, rebase, then restore local changes
git pull --rebase                          # Rebase instead of merge when pulling

--autostash is a small quality-of-life win: no more manual git stash before every rebase.

Next: Selective Updates

Rebase replays whole branches, but sometimes you only need one commit. Next, learn git cherry-pick—applying individual commits wherever you need them.