nv-worktree-create
GitHub创建Git sibling worktree及同名新分支,支持复制.env文件、初始化企业子模块并切换工作目录。适用于用户请求并行分支开发或/worktree命令场景。
Trigger Scenarios
Install
npx skills add novuhq/novu --skill nv-worktree-create -g -y
SKILL.md
Frontmatter
{
"name": "nv-worktree-create",
"description": "Create a sibling git worktree and a new branch with the same name, copy local `.env` files, optionally initialize the enterprise submodule (`--enterprise`), and move the agent into the worktree. Use when the user asks for a worktree, parallel branch checkout, or `\/worktree` with a branch name.",
"disable-model-invocation": true
}
Create a sibling git worktree
Goal: one name → new branch + sibling worktree at ../<name>, ready to work in.
For git command details and path naming, read nv-worktree-commands. For cleanup, read nv-worktree-cleanup.
Inputs
| Input | Required | Default |
|---|---|---|
| Branch / worktree name | yes — ask if missing | — |
| Base ref | no | current HEAD |
--lite |
no | off — copy only the core app .env files (api, worker, ws, dashboard), no dirty-check |
--no-env |
no | off — skip the env copy entirely |
--enterprise |
no | off — also link/init the enterprise .source submodule (slow: network + symlinks) |
Use the name as-is for the git branch. Use the sanitized name for the directory (see nv-worktree-commands).
Steps
-
Preflight — one call from the main repo root:
git rev-parse --show-toplevel && git worktree list && git status --porcelainAbort if the target path already exists. If the status is non-empty, warn that the working tree is dirty and ask whether to proceed (skip this ask with
--lite). -
Create — always a new branch and worktree:
git worktree add -b <branch> <worktree-path> [<base-ref>]Omit
<base-ref>to branch from currentHEAD. -
Copy local env files — only the gitignored
.envfiles (the.env.*variants are tracked and already in the worktree). Use the fastgit ls-filesrecipe innv-worktree-commands(~0.1s). With--liteuse its core-apps recipe; with--no-envskip. Do not use a recursiversyncover the repo (walksnode_modules/.nx, ~10s). Report what was copied. Do not runsetup-env-files.js— it regenerates encryption keys. -
Enterprise submodule — only with
--enterprise; otherwise skip and continue in OSS mode. From the worktree root (best-effort; do not block handoff):- Skip if
.sourcealready exists or is linked. - Prefer linking an existing
packages-enterpriseclone before submodule init — same candidates as.cursor/scripts/install.sh(sibling../packages-enterprise, parent checkout.source,/agent/repos/packages-enterprise, etc.). - Else configure HTTPS git fallback when SSH is unavailable, then shallow-init
.source(matchesinstall.sh):git config --global url."https://github.com/".insteadOf "git@github.com:" gh auth setup-git git submodule update --init --depth 1 .source - If
.sourceis available, refresh symlinks (warn-only on failure):pnpm symlink:submodules || echo "WARN: symlink:submodules failed; continuing in OSS mode" - If enterprise setup fails, warn and continue in OSS mode — do not block the worktree. For troubleshooting, read
enterprise-submodule.
- Skip if
-
Hand off —
move_agent_to_rootwith the absolute worktree path. Notmove_agent_to_cloned_root. -
Confirm — branch name, worktree path, base ref, copied env files, enterprise submodule status (or "skipped").
Example
User: /worktree branch=more-dcr-oauths
Branch: more-dcr-oauths
Path: ../more-dcr-oauths
Command: git worktree add -b more-dcr-oauths ../more-dcr-oauths
Then copy .env, move_agent_to_root. Add --enterprise to also wire .source + pnpm symlink:submodules.
Do not
- Check out an existing branch — this skill always creates a new branch.
- Copy the whole repo — only
.env. - Run
pnpm install,pnpm build, orpnpm setup:agent— never, not even if a task fails; tell the user instead. (pnpm symlink:submodulesunder--enterpriseis the only pnpm script allowed.) - Symlink
node_modulesfrom the parent checkout. - Pick the branch name without the user providing it (or confirming a suggested name).
Version History
-
b30b8ce
Current 2026-10-20 05:03
优化性能,改用git ls-files替代rsync加速.env复制;新增--lite和--no-env参数控制环境变量复制行为。
- 56a8a16 2026-08-29 05:10


