Create Git Worktree banner
disler disler

Create Git Worktree

Git community intermediate

Description

Create a new git worktree for an agent to work in isolation.

Installation

This entry records only its repository, not the path inside it, so there is no exact command to give. Open the source below and copy the folder into ~/.claude/skills/, or the file into ~/.claude/agents/.

Repository README

This is the README for disler/nano-agent, shared by 3 entries in this directory. It describes the repository, not this entry specifically.

Create Git Worktree

Create a new git worktree for an agent to work in isolation.

Variables

worktree_name: $ARGUMENTS (IMPORTANT: first argument) WORKTREE_PATH: trees

Instructions

Execute ALL the following steps in sequence WITHOUT using a todo list:

  1. Parse the variables - extract the worktree_name from the first argument
  2. List existing worktrees to check for name conflicts
  3. Create a new git worktree in the trees/ directory
  4. Base the worktree on the main branch
  5. Copy the .env file from the root directory to the worktree (if it exists)
  6. Create an initial commit in the worktree to establish the branch
  7. Report the successful creation of the worktree

Git Worktree Setup

Execute these steps in order:

  1. **List existing worktrees to avoid collisions**:

    git worktree list

    **WARNING**: DO NOT use any of the existing worktree names shown above! Each worktree must have a unique name.

    • Check if the proposed appears in the list
    • If it does, STOP and report: "Worktree name '' is already in use. Please choose a different name."
  2. **Create the trees directory** if it doesn't exist:

    mkdir -p trees
  3. **Check if worktree directory already exists**:

    • If trees/ already exists, report that it exists and stop
    • Otherwise, proceed with creation
  4. **Create the git worktree**:

    git worktree add trees/ -b 
  5. **Copy environment file** (if exists):

    if [ -f .env ]; then
      cp .env trees//.env
      echo "Copied .env file"
    else
      echo ".env file not found in root, skipping"
    fi
  6. **Create initial commit with no changes**:

    git -C trees/ commit --allow-empty -m "Initial worktree setup for "

Error Handling

  • If the worktree name is already in use, report this immediately and exit: "Worktree name '' is already in use. Please choose a different name."
  • If the worktree directory already exists, report this and exit gracefully
  • If git worktree creation fails, report the error
  • If .env doesn't exist in root, continue without error (it's optional)

Verification

After setup, verify the worktree was created:

ls -la trees/  # Should show full repository contents
git -C trees/ branch  # Should show the new branch

Report

Report one of the following:

  • Success: "Worktree '' created successfully at trees/"
  • Already exists: "Worktree '' already exists at trees/"
  • Error: "Failed to create worktree: "

Notes

  • Git worktrees provide branch isolation with separate working directories
  • Each worktree has its own branch and can be worked on independently
  • The worktree is created in the trees/ directory to keep them org