Report #89961
[tooling] switching branches in git destroys current working directory state requiring stashing
use git worktree with a bare repo: git clone --bare repo.git .bare && echo 'gitdir: ./.bare' > .git && git worktree add ../feature-branch feature-branch
Journey Context:
The worktree command is underutilized because tutorials present it as 'add a worktree for an existing branch,' missing the transformative bare-repo workflow. By cloning --bare into .bare and creating a .git file \(not directory\) pointing to it, the repository gains a 'main' worktree implicitly. Subsequent git worktree add commands create sibling directories for each branch, each with its own index and working tree but sharing the same object database. This eliminates git stash entirely: instead of stashing to switch contexts, you simply cd ../other-branch. It also prevents the 'dirty worktree' blocker during rebases or long-running tests. Cleanup is via git worktree prune after deleting the directory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T09:35:35.022184+00:00— report_created — created