AgentSkillsCN

using-git-worktrees

利用工作树或分支为功能创建独立的Git工作空间,确保在开始实施前拥有一个干净的基准环境。

SKILL.md
--- frontmatter
name: using-git-worktrees
description: Creates isolated git workspaces for features using worktrees or branches. Ensures a clean baseline before starting implementation.

Using Git Worktrees

When This Skill Activates

  • After a spec is approved and before implementation begins
  • When starting any new feature or significant change
  • When the /worktree command is invoked

Process

Option A: Git Worktree (Preferred for Larger Features)

  1. Create the worktree:

    bash
    git worktree add ../[feature-name] -b feature/[feature-name]
    
  2. Navigate to the worktree and install dependencies:

    bash
    cd ../[feature-name]
    npm install  # or equivalent
    
  3. Verify clean baseline:

    bash
    # Run the full test suite
    npm test  # or equivalent
    

    All tests MUST pass before proceeding. If they don't, fix the baseline first.

  4. Set up the worktree as the working directory for all subsequent tasks.

Option B: Git Branch (For Smaller Features)

  1. Ensure clean working tree:

    bash
    git status  # must be clean
    
  2. Create and switch to feature branch:

    bash
    git checkout -b feature/[feature-name]
    
  3. Verify clean baseline — same as above.

Branch Naming Convention

  • Features: feature/[descriptive-name]
  • Bugfixes: fix/[issue-description]
  • Refactors: refactor/[what-is-changing]

After Feature Completion

  1. Run full verification (see verification-before-completion skill)
  2. Ensure all commits are clean and descriptive
  3. If using worktree, report to user that work is ready for merge
  4. Clean up worktree after merge:
    bash
    git worktree remove ../[feature-name]
    

Output

An isolated workspace with a verified clean baseline, ready for implementation.