Skip to the guide

git worktree the simple guide

This guide assumes branches, commits, and checkouts already feel familiar. If they don’t, start with git — the simple guide (opens in a new tab).

the problem

two branches.
one machine.
both open.

You’re fixing main, but your half-finished feature needs to stay exactly where it is. A worktree gives another branch its own folder while sharing the same repository history.

  1. 1 Start inside your existing repository.
  2. 2 Pick a sibling folder and the existing branch you want.
  3. 3 Open both folders. That’s it.
from my-app/
$ git worktree add \
  ../my-app-login \
  feature/login

Need a new branch instead? Add -b before the new branch name: git worktree add ../my-app-login -b feature/login

tidying up

list what’s there.
remove what’s done.

Two commands to help you clean up after yourself.

01 / look

what do I have?

$ git worktree list
/code/my-app[main]
/code/my-app-login[feature/login]
02 / tidy

I’m finished.

$ git worktree remove \
  ../my-app-login

Remove the folder when its work is committed. The branch stays safe in Git; only the extra working folder goes away.

add. work. list. remove. that’s the whole guide.

command copied