Agent Skillsnovuhq/novu › nv-worktree-commands

nv-worktree-commands

GitHub

提供Git worktree命令参考,涵盖路径命名、创建/移除、本地.env文件同步及依赖安装。用于实现或调试worktree环境配置,辅助开发流程自动化。

.cursor/skills/nv-worktree-commands/SKILL.md novuhq/novu

Trigger Scenarios

需要创建新的git工作树 调试多工作树环境配置 同步本地环境变量到工作树

Install

npx skills add novuhq/novu --skill nv-worktree-commands -g -y
More Options

Use without installing

npx skills use novuhq/novu@nv-worktree-commands

指定 Agent (Claude Code)

npx skills add novuhq/novu --skill nv-worktree-commands -a claude-code -g -y

安装 repo 全部 skill

npx skills add novuhq/novu --all -g -y

预览 repo 内 skill

npx skills add novuhq/novu --list

SKILL.md

Frontmatter
{
    "name": "nv-worktree-commands",
    "description": "Git worktree command reference: path naming, create\/remove\/prune, `.env*` copy, package-manager install, and cleanup. Use when implementing or debugging worktree setup — not as the primary user-facing workflow (see nv-worktree-create)."
}

Git worktree commands

Reference for agents implementing worktree workflows. Prefer nv-worktree-create for the end-to-end flow.

Path naming

REPO_ROOT  = $(git rev-parse --show-toplevel)
REPO_PARENT = $(dirname "$REPO_ROOT")
BRANCH     = user-provided name (used as git branch)
DIR_NAME   = sanitize(BRANCH)   # lowercase; `/` → `-`
WORKTREE   = "$REPO_PARENT/$DIR_NAME"

Examples (repo at /Users/me/work/novu):

Branch Worktree path
more-dcr-oauths /Users/me/work/more-dcr-oauths
nv-1234/foo-bar /Users/me/work/nv-1234-foo-bar

Abort if WORKTREE already exists on disk or in git worktree list.

Create (new branch)

From current HEAD:

git worktree add -b <branch> <worktree-path>

From a specific base:

git worktree add -b <branch> <worktree-path> <base-ref>

<base-ref>: HEAD, main, origin/main, a tag, or a commit SHA.

Inspect

git worktree list
git -C <worktree-path> status -sb
git -C <worktree-path> rev-parse HEAD

Copy local env files

git worktree add does not bring gitignored files. Copy local secret env files only from the main checkout — not .env.example / .env.template (those are already in git).

Preferred — rsync with explicit includes (from main repo root):

rsync -a \
  --prune-empty-dirs \
  --include='*/' \
  --include='.env' \
  --include='.env.*' \
  --exclude='.env.example' \
  --exclude='.env.template' \
  --exclude='*' \
  --exclude='node_modules/' \
  --exclude='dist/' \
  --exclude='build/' \
  --exclude='.next/' \
  --exclude='.turbo/' \
  "<main-repo-root>/" "<worktree-path>/"

Alternative — copy only gitignored env files (when rsync is unavailable):

cd <main-repo-root>
git ls-files -z --others --ignored --exclude-standard \
| while IFS= read -r -d '' f; do
    base="$(basename "$f")"
    case "$base" in
      .env|.env.*)
        case "$base" in
          .env.example|.env.template) continue ;;
        esac
        mkdir -p "<worktree-path>/$(dirname "$f")"
        cp -a "$f" "<worktree-path>/$f"
        ;;
    esac
  done

After copying, list what landed (e.g. find <worktree-path> -type f \( -name '.env' -o -name '.env.*' \) ! -name '.env.example' ! -name '.env.template').

Novu-specific

  • Copy from the parent checkout, not node scripts/setup-env-files.js. That script generates a new STORE_ENCRYPTION_KEY when .env is missing — a worktree would then disagree with the parent and shared local Mongo/Redis.
  • Typical files copied: apps/api/src/.env, .env.agent, .env.development, apps/dashboard/.env, apps/worker/src/.env, apps/ws/src/.env, etc.
  • Skip playground/ env unless the task needs it.

Install dependencies

Lockfile Command
pnpm-lock.yaml pnpm install
yarn.lock yarn install
package-lock.json npm install
bun.lockb bun install

Run from the worktree root.

Build

pnpm build   # or npm/yarn/bun equivalent

Skip if no build script exists.

Remove

git worktree remove <worktree-path>
git worktree prune

Remove uncommitted work in the worktree first, or use --force only when the user explicitly asks.

For auditing merged/stale worktrees and batch cleanup, read nv-worktree-cleanup.

Anti-patterns

  • git worktree add --detach when the goal is a named feature branch — use -b.
  • cp -r the entire repo instead of git worktree add.
  • Reusing ~/.cursor/worktrees/… detached paths when a sibling ../<name> worktree is enough.
  • Running full setup scripts (pnpm setup:agent) in Cursor Cloud child worktrees when the parent already ran them.

Version History

  • 56a8a16 Current 2026-08-29 05:10

Same Skill Collection

.agents/skills/email-best-practices/SKILL.md
.agents/skills/frontend-design/SKILL.md
.agents/skills/linear-release-setup/SKILL.md
.agents/skills/react-email/SKILL.md
.agents/skills/testerarmy-cli/SKILL.md
.claude/skills/better-auth-best-practices/SKILL.md
.cursor/skills/add-channel-connect-button/SKILL.md
.cursor/skills/add-channel-setup-guide/SKILL.md
.cursor/skills/address-pr-review/SKILL.md
.cursor/skills/better-auth-best-practices/SKILL.md
.cursor/skills/ink-tui/SKILL.md
.cursor/skills/novu-prepare-pr/SKILL.md
.cursor/skills/nv-implement/SKILL.md
.cursor/skills/nv-park-and-review/SKILL.md
.cursor/skills/nv-worktree-cleanup/SKILL.md
.cursor/skills/nv-worktree-create/SKILL.md
.cursor/skills/run-api-e2e-tests/SKILL.md
.cursor/skills/sanity-changelog/SKILL.md
.cursor/skills/triage-agent-eval-failures/SKILL.md
docs/.mintlify/skills/dashboard-workflows/SKILL.md
docs/.mintlify/skills/manage-preferences/SKILL.md
docs/.mintlify/skills/manage-subscribers/SKILL.md
docs/.mintlify/skills/trigger-notification/SKILL.md
.agents/skills/figma-use/SKILL.md
.cursor/skills/add-channel-whats-next-onboarding/SKILL.md
.cursor/skills/nv-endpoint-routed-tool-provider/SKILL.md
docs/.mintlify/skills/design-workflow/SKILL.md
docs/.mintlify/skills/framework-integration/SKILL.md
docs/.mintlify/skills/inbox-integration/SKILL.md

Metadata

Files
0
Version
56a8a16
Hash
e374c450
Indexed
2026-08-29 05:10

Accueil - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-31 23:46
浙ICP备14020137号-1 $Carte des visiteurs$