Practical Git techniques for worktrees, bisect, cherry-pick, and interactive rebase.
Key takeaways
- Git worktrees let you check out multiple branches in separate directories simultaneously.
- Git bisect uses binary search to find a bug-introducing commit in minutes instead of hours.
- Cherry-pick applies any commit from any branch to your current branch without a full merge.
- Named stashes created with git stash push -m stay manageable even when you accumulate several.
- Interactive rebase lets you squash, reorder, or reword commits before pushing to a shared branch.
Use git worktree instead of stashing for context switches
The classic problem: you are mid-feature when production breaks. git stash saves your changes but can ruin node_modules, active dev servers, and anything else that tracks file state. A worktree creates a completely separate directory where you can run a full dev environment without touching your current branch.
The command git worktree add -b emergency-fix ../my-app-fix main creates a new branch in a sibling folder. Push the fix, remove the worktree, and return to your feature branch exactly as you left it.
- Run git worktree add -b hotfix-name ../folder-name main to create a new branch checked out in a separate directory.
- Both directories share the same repository — commits in one are immediately visible from the other.
- Remove the worktree when done with git worktree remove ../folder-name; the branch itself stays intact.
Find the exact commit that broke something with git bisect
When a bug exists now but did not exist three weeks ago, the naive approach is manually checking recent commits one by one. git bisect turns that into a binary search, finding the culprit in log2(N) steps instead of N.