Sync selected ignored files and directories into newly created Git worktrees.
Useful for local files that Git does not track, such as .env, .env.local, node_modules, or .turbo.
pnpm add -D branchstashCreate the default config:
pnpm branchstash initThis adds a minimal package.json block:
{
"branchstash": {
"files": {
".env": "link",
"node_modules": "copy"
}
}
}Supported strategies:
copy: create an independent copy, using CoW/reflink when possiblelink: create a symlink to the source worktree path
pnpm branchstash installThis installs a post-checkout Git hook that delegates to the installed CLI with an absolute path:
node "/absolute/path/to/branchstash/dist/cli.js" run "$@"The hook is idempotent and preserves unrelated existing hook content where possible.
Create a worktree normally:
git worktree add ../project-feature -b feature/my-featureThe hook runs automatically for newly created worktrees.
You can also run manually:
pnpm branchstash runManual runs are useful if the hook was not installed yet, config changed, or files were deleted.
- Source is the main worktree from
git worktree list --porcelain. - Target is the current worktree.
- Only explicitly configured paths are synced.
- Missing source paths are skipped.
- Existing target paths are skipped.
- Targets are never overwritten by default.