Skip to main content

Sign in

Save your progress and access it from any device.

Or with email

Don't have an account?

Privacy policy

Git worktree: work on multiple branches

git worktree lets you work on multiple branches at the same time, each in its own directory. No more stashing to switch branches.

When to use git worktree?

Urgent bug in parallel

You are working on a feature but an urgent bug comes in. Create a worktree for the hotfix without touching your work in progress.

Compare two branches

Open two branches side by side in your editor to compare code or test different implementations.

Long build in progress

While a build runs on one branch, keep coding on another in a separate worktree.

Git worktree in practice

Creating and managing worktrees.

Creating a worktree

Managing worktrees

worktree vs stash + switch

git worktree

Each branch has its own directory. No stashing, no context switching. You keep everything open.

Ideal for extended multitasking

stash + switch

Temporary save then branch switch. A single directory, you alternate between branches.

Ideal for a quick switch

Common mistakes with git worktree

Forgetting to remove worktrees

Worktrees take up disk space. Remember to remove them with git worktree remove when you no longer need them.

Deleting the folder instead of using remove

If you delete the directory manually, Git keeps orphaned references. Use git worktree prune to clean up.

Trying to checkout the same branch

A branch can only be in one worktree at a time. If you need to work on the same branch, create a temporary new branch.

Part of the Git Advanced guide

A

GitQuest is created by Anaïs (nouvelle fenêtre), web developer and head of education, specializing in tech training and digital accessibility.

Questions about git worktree

Become a multitasker with GitQuest

Learn to juggle between branches and worktrees like a pro.

Start the investigations