Create a worktree without checking out files

basics

// what it does

--no-checkout registers the worktree and sets its branch but writes no files, leaving room to configure things — most commonly sparse-checkout — before materializing the tree. In a large monorepo this avoids ever writing the hundreds of thousands of files you don't need.

// shell

$ git worktree add --no-checkout -b agent-docs ../myapp-docs main
$ cd ../myapp-docs && git sparse-checkout set docs && git checkout

// gotcha

Until you run git checkout inside it, the worktree is an empty directory where git status looks alarming (everything shows as deleted). Finish the setup before pointing tools or agents at it.

// resources