Parallel Work Workshop
Practice using worktrees and stashing to manage multiple tasks simultaneously.
Setup
Create a repository to practice with:
bash1$ mkdir parallel-practice && cd parallel-practice2$ git init34$ echo "# Project" > README.md5$ git add README.md6$ git commit -m "initial commit"78$ echo "console.log('app');" > app.js9$ git add app.js10$ git commit -m "add app.js"
Part 1: Worktrees
Exercise 1: Create a Hotfix Worktree
Imagine you're working on a feature when an urgent bug report comes in.
bash1# Create a branch for the hotfix2$ git branch hotfix/urgent-fix34# Create a worktree for it5$ git worktree add ../parallel-practice-hotfix hotfix/urgent-fix6Preparing worktree (checking out 'hotfix/urgent-fix')7HEAD is now at abc1234 add app.js
Exercise 2: List Your Worktrees
bash1$ git worktree list2/path/to/parallel-practice abc1234 [main]3/path/to/parallel-practice-hotfix abc1234 [hotfix/urgent-fix]
Exercise 3: Work in the Hotfix Worktree
bash1$ cd ../parallel-practice-hotfix23# Make the hotfix4$ echo "console.log('fixed!');" >> app.js5$ git add app.js6$ git commit -m "fix: urgent bug"78# Verify9$ git log --oneline -210def5678 fix: urgent bug11abc1234 add app.js
Exercise 4: Return and Remove Worktree
bash1# Go back to main project2$ cd ../parallel-practice34# Remove the hotfix worktree5$ git worktree remove ../parallel-practice-hotfix67# Verify it's gone8$ git worktree list9/path/to/parallel-practice abc1234 [main]
Exercise 5: Create Worktree with New Branch
bash1# Create worktree with a new branch in one command2$ git worktree add -b feature/new-thing ../parallel-practice-feature main3Preparing worktree (new branch 'feature/new-thing')4HEAD is now at abc1234 add app.js56# Verify7$ git worktree list8/path/to/parallel-practice abc1234 [main]9/path/to/parallel-practice-feature abc1234 [feature/new-thing]
Clean up:
bash1$ git worktree remove ../parallel-practice-feature
Part 2: Stashing
Exercise 6: Basic Stash
Make some uncommitted changes:
bash1$ echo "work in progress" >> app.js2$ echo "new file" > wip.txt34$ git status5Changes not staged for commit:6 modified: app.js78Untracked files:9 wip.txt
Stash them (note: untracked files need -u):
bash1$ git stash push -u -m "WIP: feature work"2Saved working directory and index state On main: WIP: feature work34$ git status5On branch main6nothing to commit, working tree clean
Exercise 7: List and Show Stashes
bash1$ git stash list2stash@{0}: On main: WIP: feature work34$ git stash show5 app.js | 1 +6 wip.txt | 1 +7 2 files changed, 2 insertions(+)89$ git stash show -p
Exercise 8: Do Other Work While Stashed
bash1# Simulate urgent work2$ echo "urgent change" > urgent.txt3$ git add urgent.txt4$ git commit -m "feat: urgent feature"56$ git log --oneline -27ghi9012 feat: urgent feature8abc1234 add app.js
Exercise 9: Restore Stashed Work
bash1$ git stash pop2On branch main3Changes not staged for commit:4 modified: app.js56Untracked files:7 wip.txt89Dropped refs/stash@{0} (xyz...)1011$ cat app.js12console.log('app');13work in progress
Your work is restored!
Exercise 10: Multiple Stashes
Create several stashes:
bash1# First stash2$ echo "change 1" >> app.js3$ git stash push -m "change 1"45# Second stash6$ echo "change 2" >> app.js7$ git stash push -m "change 2"89# Third stash10$ echo "change 3" >> app.js11$ git stash push -m "change 3"1213$ git stash list14stash@{0}: On main: change 315stash@{1}: On main: change 216stash@{2}: On main: change 1
Apply a specific stash:
bash1$ git stash apply stash@{1}23$ cat app.js4console.log('app');5work in progress6change 2
Exercise 11: Drop and Clear Stashes
bash1# Drop one stash2$ git stash drop stash@{0}3Dropped stash@{0} (abc...)45$ git stash list6stash@{0}: On main: change 27stash@{1}: On main: change 189# Clear all remaining stashes10$ git stash clear1112$ git stash list13# (empty)
Exercise 12: Interactive Stashing
Make multiple changes:
bash1$ git checkout -- app.js # Reset to clean state2$ echo "keep this" >> app.js3$ echo "stash this" >> README.md
Stash only README changes:
bash1$ git stash push -p -m "selective stash"2# Git will prompt for each hunk3# Press 'y' for README.md changes4# Press 'n' for app.js changes
Check the result:
bash1$ git status2Changes not staged for commit:3 modified: app.js4 # README.md changes are stashed56$ git stash show7 README.md | 1 +8 1 file changed, 1 insertion(+)
Cleanup
bash1$ cd ..2$ rm -rf parallel-practice parallel-practice-hotfix parallel-practice-feature
Worktrees vs Stashing: When to Use Which
| Situation | Best Choice |
|---|---|
| Quick 5-minute context switch | Stash |
| Hotfix while working on feature | Worktree |
| Running tests in background | Worktree |
| Saving work before risky operation | Stash |
| Multiple PRs in progress | Worktrees |
| Brief branch check | Stash |
Checklist
- Created a worktree for a branch
- Listed all worktrees
- Made commits in a worktree
- Removed a worktree
- Created a worktree with a new branch
- Stashed uncommitted changes
- Listed and showed stash contents
- Applied and popped stashes
- Managed multiple stashes
- Used interactive stashing
Key Takeaway
Worktrees = separate directories for parallel work (heavy). Stashing = quick save/restore in same directory (light). Both prevent losing work when context switching.