SmartGirls Skill
to navigate 01 / 09
Skill Session
01 / 09
SmartGirls Skill Template Engineering Fundamentals
Duration ~ 15 min
Level: beginner-friendly

github
worktrees.

Work on multiple branches at once without juggling stashes, clones, or context-switching tax. A practical primer for people who already use git.

Prepared by SmartGirls Skill Library
Format 9 slides, hands-on
The Problem
02 / 09
why this exists

One working directory is a bottleneck.

You are halfway through a feature on feature/login. A teammate pings: "the build is broken on main, can you look?"

Now you stash your work, switch branches, investigate, switch back, pop the stash, and hope nothing collided. Multiply by ten interruptions a week.

Worktrees sidestep the whole dance.

# the familiar pain $ git stash Saved working directory and index state $ git checkout main $ # ...investigate, fix, commit... $ git checkout feature/login $ git stash pop Auto-merging src/auth.ts CONFLICT (content): Merge conflict # ugh.
Stash pop collision - the classic trap
1 Stashing saves uncommitted work to a stack you re-apply later. Fast, but fragile across branch switches.
2 Context tax is the mental cost of reloading a branch's state into your head after every switch.
Definition
03 / 09
the core idea

A worktree is a second checkout of the same repo.

Same .git, same history, same remotes. A separate folder on disk where a different branch lives, ready to work in. No clone, no stash, no ceremony.

.git (shared) objects, refs, config ~/project/ on branch: main your usual working folder ~/project-feature/ on branch: feature/x a second checkout, same repo
1 One .git, many folders. Branches you check out into worktrees cannot be checked out in two places at once - git protects you from that race.
Hands-on
04 / 09
the one command

Three words, one new folder.

# from inside your repo git worktree add ../project-hotfix # or, name the branch too git worktree add -b hotfix/login ../project-hotfix # list what you have open git worktree list
The full vocabulary you need to start

The first form creates a new folder one level up, checks out the current branch's tip into a new branch, and wires it to the shared .git.

The -b flag lets you name the branch at the same time. Common when you want a clean branch for the work.

Open the new folder in a second editor window. That is the whole workflow.

1
shared .git directory. No duplicate history, no extra disk bloat beyond the working files.
1 Path matters. Worktrees usually live outside the main repo folder to avoid nested-git confusion.
2 Editor support. VS Code, JetBrains, and Neovim all open worktrees as independent project roots.
Before / After
05 / 09
the difference, side by side

Stash-and-switch vs. worktree.

With worktrees
  • Open a second folder, keep coding
  • Both branches visible at once
  • No stash, no pop, no conflicts
  • Editor state preserved per branch
  • Tests can run in parallel
  • Switching is instant - it is just a window
The old way
  • Stash, switch, investigate, switch back
  • One branch visible at a time
  • Stash pop can collide
  • Editor tabs and scroll reset each time
  • Long-running tasks block the branch
  • Each switch reloads context into your head
1 Cost. Worktrees use disk for the working files only - history stays in the shared .git. A 500MB repo's worktree is roughly 500MB more, not a full re-clone.
Lifecycle
06 / 09
add, use, remove

A worktree is temporary by design.

1 add git worktree add ../project-fix 2 work code, commit, push merge when ready 3 remove git worktree remove ../project-fix
# clean up when done git worktree remove ../project-fix # force if uncommitted changes git worktree remove --force ../project-fix # prune stale entries git worktree prune

Removing a worktree deletes the folder and detaches it from .git. The branch you worked on stays in the repo until you delete it explicitly.

If you just delete the folder by hand, git remembers a stale entry. Run git worktree prune to tidy up.

When it shines
07 / 09
three good moments

Reach for a worktree when...

01

A hotfix lands mid-feature

You are deep in a refactor. Production breaks. Open a worktree on main, fix, ship, return - your feature branch has not moved.

02

You review a teammate's PR

Check out their branch into a worktree. Run it, poke the code, keep your own work open beside it. No branch juggling.

03

Long-running tasks block you

A migration is running on your branch. A test suite takes ten minutes. Spin up a worktree, keep working, let the slow thing finish in its own folder.

1 Rule of thumb. If switching branches would cost you more than thirty seconds of mental reset, a worktree pays for itself.
2 Not for everything. Tiny one-line fixes do not need a worktree. The tool is for parallel context, not ceremony.