Search

Search IconIcon to open search

Git Worktrees

Last updatedUpdated: by Jakub Žovák · 2 min read

Properties
tags cscs/swe
created 15.03.2026, 00:00
modified Empty
published Empty
sources Git Worktrees
topics Git, Worktrees
authors Empty
ai-assisted Yes

A git worktree allows you to check out multiple branches simultaneously into separate directories, all sharing the same .git repository. This enables parallel work without stashing or switching branches.

# Use Cases

  • Work on a hotfix while keeping your feature branch untouched
  • Run tests on one branch while developing on another
  • Review a PR in an isolated directory without context-switching

# Commands

# Create

1
2
3
git worktree add <path> <branch>          # check out existing branch into <path>
git worktree add <path> -b <new-branch>   # create new branch and check it out
git worktree add <path>                   # detached HEAD at current commit

# List & Inspect

1
2
git worktree list                         # show all worktrees with HEAD and branch
git worktree list --porcelain             # machine-readable output

# Remove

1
2
3
git worktree remove <path>                # remove worktree (must be clean)
git worktree remove --force <path>        # force-remove even with uncommitted changes
git worktree prune                        # clean up stale worktree metadata

# Move & Lock

1
2
3
git worktree move <path> <new-path>       # relocate a worktree
git worktree lock <path>                  # prevent pruning (e.g. on removable drive)
git worktree unlock <path>                # re-enable pruning

# Notes

  • Each worktree has its own working directory and index but shares refs, objects, and config
  • A branch can only be checked out in one worktree at a time
  • .git/worktrees/ stores per-worktree metadata