AgentSkillsCN

worktrees

当您开始进行孤立功能开发时,这一工具能通过创建Git工作树,有效防止分支间的相互污染。涵盖工作树、隔离开发、并行功能以及分支隔离。注意:此工具不适用于简单的分支切换(请使用git checkout),也不适用于仅限Linear的操作(请使用linear)。

SKILL.md
--- frontmatter
name: worktrees
description: Use when starting isolated feature work. Creates git worktrees to prevent branch cross-contamination. Covers worktree, isolated development, parallel features, branch isolation. NOT for: simple branch switching (use git checkout), Linear-only operations (use linear).

Git Worktrees

Create isolated working directories for each task. Worktrees share git history but have separate working files, preventing cross-contamination between branches.

Quick Actions

What you want to doWorkflow
Create new worktree from branch nameworkflows/create.md
Create worktree from Linear issueworkflows/from-linear.md
List active worktreesworkflows/list.md
Switch to a worktreeworkflows/switch.md
Clean up completed worktreesworkflows/cleanup.md

Default Paths

Worktrees are created at: ~/worktrees/<repo>/<branch>

Example:

  • Main repo: /Users/me/projects/my-app
  • Worktree: ~/worktrees/my-app/feature-login

Environment Setup (Automatic)

Worktrees automatically handle:

  • Env files: Uses 1Password op inject if .env.template exists, else copies .env*.local from source
  • Dependencies: Auto-detects package manager (bun/pnpm/yarn/npm) and installs
ConditionAction
.env.template + op availableop inject -i .env.template -o .env.local
op inject failsFallback: copy from source repo
No .env.templateCopy all .env*.local from source

Quick Commands

bash
# List all worktrees
git worktree list

# Create worktree with new branch
git worktree add ~/worktrees/$(basename "$PWD")/feature-name -b feature-name

# Remove worktree
git worktree remove ~/worktrees/$(basename "$PWD")/feature-name

# Prune stale references
git worktree prune

Troubleshooting

"fatal: 'path' already exists"

  • Worktree or directory already exists at that path
  • Remove existing directory or choose different name

"branch already exists"

  • Branch was created previously
  • Use without -b flag: git worktree add <path> <existing-branch>

"Cannot create worktree from detached HEAD"

  • Must be on a branch in main repo
  • Run git checkout main first