Start an empty orphan branch in a new worktree

internals & scripting

// what it does

--orphan creates the worktree with an empty index and an unborn branch — a fresh history with no parent commits, kept apart from your source tree. Classic uses: a gh-pages or docs-site branch, or a branch that stores generated artifacts, built without ever disturbing your main checkout.

// shell

$ git worktree add --orphan -b gh-pages ../myapp-pages
$ cd ../myapp-pages && git status

// gotcha

git worktree add --orphan arrived in Git 2.42 (2023) — older Gits reject the flag; there, fall back to git switch --orphan inside a regular worktree. The new worktree starts truly empty: no files, nothing staged, until you add and commit.

// resources