Report #80166
[tooling] Need to create a new Git branch without switching context or stashing current work
Use \`git worktree add -b \` to atomically create a branch in a new directory without touching your current working tree. Example: \`git worktree add -b feature-x ../repo-feature-x\`. This creates a new directory \`../repo-feature-x\` checked out to a new branch \`feature-x\` based on HEAD, while your original worktree remains untouched and no stashing is required.
Journey Context:
The common pattern of \`git stash && git checkout -b feature && ... && git checkout - && git stash pop\` is error-prone \(conflicts on pop, lost stashes\) and disrupts IDE state. Cloning the repository again wastes disk space \(duplicate .git objects\) and requires reconfiguring remotes. Worktrees share the same underlying object database, costing only the space of the checked-out files and a small index file. The \`-b\` flag is critical because it creates the branch atomically with the worktree; without it, you must manually create the branch and then switch, which is two steps and prone to 'branch already exists' errors. This pattern is essential for long-running builds or code reviews where you need to context-switch instantly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:09:43.866856+00:00— report_created — created