Advanced Git Workflows Cheat Sheet
Quick reference guide for Advanced Git: Interactive rebase, cherry-pick, bisect, reflog recovery, and worktrees.
Advanced Git features enable powerful commit history editing, emergency data recovery, automated bug hunting, and isolated parallel branch workspaces.
Interactive Rebase (`git rebase -i`)
Interactively edit, squash, reorder, or drop commits from history.
# Interactively rebase last 5 commits
git rebase -i HEAD~5
Rebase Todo List Commands:
| Keyword | Short | Action |
|---|---|---|
pick | p | Use commit as-is |
reword | r | Use commit, but edit commit message |
edit | e | Use commit, but stop for amending before moving on |
squash | s | Combine commit into previous commit, meld messages |
fixup | f | Combine commit into previous commit, discard message |
drop | d | Delete commit entirely from history |
Git Worktrees (`git worktree`)
Worktrees allow multiple active branches checked out in separate working directories simultaneously.
# Add a new worktree directory for feature branch
git worktree add ../my-feature-dir -b feature/login
# List all active worktrees
git worktree list
# Remove worktree after work is completed
git worktree remove ../my-feature-dir
Reflog Emergency Data Recovery
git reflog records every HEAD movement (commits, rebases, checkouts), allowing recovery of deleted commits or branches.
# View reflog history
git reflog
# Restore branch to commit before bad rebase
git reset --hard HEAD@{2}
Binary Search Bug Hunting (`git bisect`)
Automate finding the exact commit that introduced a bug using binary search.
git bisect start
git bisect bad # Current commit is broken
git bisect good v1.0.0 # Known good commit or tag
# Test commit and mark
git bisect good # (or git bisect bad)
# Reset when finished
git bisect reset
Common Pitfalls & Tips
[!WARNING] Never run
git rebase -iorgit push --forceon shared public branches likemainormaster!
[!TIP] Use
git commit --fixup <commit-hash>followed bygit rebase -i --autosquashto cleanly patch earlier commits automatically.