← Back to Mission Control

Timeline Adjustment

7 min read

Git Rebase

Mission Phase 29 • Difficulty: Advanced

Rewriting History

Rebase rewrites commit history to create a cleaner, more linear timeline. Powerful but requires caution.

Basic Rebase

# From feature branch
git rebase main

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

Rebase vs Merge

Interactive Rebase

git rebase -i HEAD~3

Edit last 3 commits. Options:

Squashing Commits

Combine multiple commits into one:

git rebase -i HEAD~3

Change to:

pick abc123 First commit
squash def456 Second commit
squash ghi789 Third commit

Resolving Rebase Conflicts

  1. Fix conflicts in files
  2. git add resolved files
  3. git rebase --continue

Aborting Rebase

git rebase --abort

Golden Rule

Never Rebase Public Commits

Don't rebase commits that have been pushed to shared branches. This rewrites history others depend on, causing chaos.

Rebase is safe for:

  • Local commits not yet pushed
  • Personal feature branches
  • Cleaning up before creating PR

When to Use Rebase

When to Use Merge

Next: Vessel Switching

Rebase is powerful but dangerous. Next, learn git switch—the modern way to change branches.