← all lessons
Advanced Workflows · lesson 11 of 18

Advanced Operations

Power User Tools

Why it matters

These commands separate beginners from power users. Master them to handle complex situations with confidence.

Key concepts

The idea

The Power Tools

cherry-pick: Copy a single commit to another branch. Like copying one chapter from one book to another.

bisect: Find which commit introduced a bug. Binary search through history—incredibly efficient.

stash: Temporarily hide changes. Like putting papers in a drawer while you clean your desk.

rebase -i: Rewrite history. Edit, squash, reorder, or drop commits before sharing.

Walkthrough

Cherry-Pick

# Copy commit abc123 to current branch
git cherry-pick abc123

# Cherry-pick without committing (just apply changes)
git cherry-pick --no-commit abc123

# Cherry-pick a range
git cherry-pick abc123..def456

Use case: Backport a bugfix from main to a release branch.

Bisect (Binary Search for Bugs)

# Start bisect session
git bisect start

# Mark current commit as bad
git bisect bad

# Mark known good commit
git bisect good v1.0

# Git checks out middle commit
# Test, then mark it:
git bisect good  # or
git bisect bad

# Repeat until Git finds the culprit
# When done:
git bisect reset

Automated bisect:

git bisect run ./test-script.sh
# Returns 0 = good, 1+ = bad

Stash

# Save current changes
git stash

# Save with message
git stash push -m "Work in progress on login"

# List stashes
git stash list

# Apply most recent stash (keep in list)
git stash apply

# Apply and remove from list
git stash pop

# Apply specific stash
git stash apply stash@{2}

# Drop a stash
git stash drop stash@{0}

Interactive Rebase

# Rebase last 5 commits interactively
git rebase -i HEAD~5

Opens editor with commands:

pick abc123 First commit
pick def456 Second commit
squash ghi789 Third commit (squash into second)
reword jkl012 Fourth commit (edit message)
drop mno345 Fifth commit (remove entirely)

Commands:

Key takeaways

Dos & don’ts

✅ DO

❌ DON’T

Going deeper

The reflog protects you: Even after dangerous operations, reflog keeps references for 90 days. git reflog shows all HEAD movements. You can recover almost anything.

Autosquash workflow:

  1. Make fix: git commit --fixup abc123
  2. Later: git rebase -i --autosquash main
  3. Git automatically reorders and squashes

Common mistakes

Cherry-pick conflicts: The commit may depend on earlier changes not present in target branch. You’ll need to resolve conflicts manually.

Interactive rebase on wrong branch: Always double-check which branch you’re on before rebase -i. git branch shows current branch with asterisk.