Strategic Merge vs Rebase
You are now operating at elite command level. These advanced techniques require precision and deep understanding of Git's internal mechanisms.
Welcome to your first Commander-level operation, Space Commander! You've mastered the basics of timeline convergence through simple merges and rebases during your cadet training. Now you'll learn the sophisticated decision-making and advanced techniques that separate rookie astronauts from seasoned space commanders.
In complex multi-ship operations across the galaxy, deciding when to merge vs when to rebase can mean the difference between a clean mission history and a chaotic timeline that confuses your entire crew. As a Commander, you must understand not just how these operations work, but when and why to use each approach.
Merge: Preserves complete history with all parallel development visible.
Rebase: Creates clean, linear history by replaying commits.
# Merge: Shared branches, feature integration
git checkout main
git merge feature-branch
# Rebase: Local cleanup before sharing
git checkout feature-branch
git rebase main
Edit commit history before sharing:
# Start interactive rebase
git rebase -i HEAD~4
# Editor shows:
pick 1a2b3c4 Add navigation
pick 5d6e7f8 Fix bug
pick 9g0h1i2 Add feature
pick 3j4k5l6 Fix typo
# Commands:
# pick (p) = use commit
# reword (r) = edit message
# squash (s) = combine with previous
# fixup (f) = squash but discard message
# drop (d) = remove commit
# Example: Squash last 2 commits
pick 1a2b3c4 Add navigation
pick 5d6e7f8 Fix bug
pick 9g0h1i2 Add feature
squash 3j4k5l6 Fix typo
Never rebase commits that have been shared with your crew (pushed to shared repositories). This rewrites mission history and can cause severe timeline desynchronization.
⚠️ **Never rebase shared/pushed commits!**
# If rebase goes wrong
git rebase --abort
# Create backup before risky operations
git branch backup-before-rebase
# Check reflog to recover
git reflog
git reset --hard HEAD@{2}
mkdir practice && cd practice && git init
# Create messy commits
echo "v1" > file.txt && git add . && git commit -m "add stuff"
echo "v2" >> file.txt && git add . && git commit -m "debug"
echo "v3" >> file.txt && git add . && git commit -m "temp"
echo "v4" >> file.txt && git add . && git commit -m "final"
# Clean up with interactive rebase
git rebase -i HEAD~4
# Change to:
# pick (first commit)
# squash (second)
# squash (third)
# squash (fourth)
# Result: One clean commit!
You've mastered merge vs rebase strategies and interactive rebase.
Your next commander operation will cover Advanced Branching Strategies, where you'll learn enterprise-level branch management and workflow patterns used by elite development teams across the galaxy.