git-worktrees-worktree-management

$npx mdskill add TheBushidoCollective/han/git-worktrees-worktree-management

Isolate and integrate work by managing git worktrees.

  • Lists active worktrees, prunes stale ones, and merges work back.
  • Uses Bash, Read, Glob, and Grep tools to execute commands.
  • Executes commands based on user input to list, prune, or merge.
  • Outputs formatted text showing worktree status and commit history.

SKILL.md

.github/skills/git-worktrees-worktree-managementView on GitHub ↗
---
name: git-worktrees-worktree-management
description: Manage git worktrees - list active worktrees, prune stale ones, and merge work back into the main branch.
allowed-tools:
  - Bash
  - Read
  - Glob
  - Grep
---

# Worktree Management

## Name

git-worktrees:worktree-management - Manage git worktrees created by subagents

## Synopsis

```
/worktree-management [list|prune|merge]
```

## Description

Manages git worktrees that were created by subagents for isolation. Provides commands to list active worktrees, prune stale ones, and merge completed work back into the current branch.

## Implementation

### List Worktrees

Show all active worktrees and their status:

```bash
git worktree list
```

For worktrees in the `.worktrees/` directory, also show their commit status:

```bash
for wt in .worktrees/*/; do
  if [ -d "$wt" ]; then
    echo "=== $(basename "$wt") ==="
    git -C "$wt" log --oneline -5
    echo ""
  fi
done
```

### Prune Stale Worktrees

Remove worktrees that are no longer needed:

```bash
# Remove all worktrees in .worktrees/
git worktree list --porcelain | grep "^worktree " | grep ".worktrees/" | while read -r line; do
  wt_path="${line#worktree }"
  git worktree remove "$wt_path"
done

# Clean up any stale entries
git worktree prune
```

### Merge Work Back

To merge a specific worktree's work into the current branch:

1. Identify the worktree and its commits
2. Cherry-pick or merge the commits into the main working tree
3. Remove the worktree after successful merge

```bash
# From the main working tree:
WORKTREE_NAME="agent-xxx"
WORKTREE_BRANCH=$(git -C ".worktrees/${WORKTREE_NAME}" rev-parse HEAD)

# Cherry-pick the commits
git cherry-pick "${WORKTREE_BRANCH}"

# Or create a merge
git merge "${WORKTREE_BRANCH}" --no-ff -m "merge: integrate work from ${WORKTREE_NAME}"

# Clean up
git worktree remove ".worktrees/${WORKTREE_NAME}"
```

## Example Interaction

**User:** List my active worktrees

**Agent:**
```
$ git worktree list
/path/to/repo                  abc1234 [main]
/path/to/repo/.worktrees/agent-1707123456-12345  def5678 (detached HEAD)
/path/to/repo/.worktrees/agent-1707123789-67890  ghi9012 (detached HEAD)

=== agent-1707123456-12345 ===
def5678 feat: implement user authentication
abc1234 Initial commit

=== agent-1707123789-67890 ===
ghi9012 fix: resolve database connection issue
abc1234 Initial commit
```

**User:** Merge the auth worktree and clean up

**Agent:** Cherry-picks the auth commit, removes the worktree, and prunes stale entries.

More from TheBushidoCollective/han

SkillDescription
absinthe-resolversUse when implementing GraphQL resolvers with Absinthe. Covers resolver patterns, dataloader integration, batching, and error handling.
absinthe-schemaUse when designing GraphQL schemas with Absinthe. Covers type definitions, interfaces, unions, enums, and schema organization patterns.
absinthe-subscriptionsUse when implementing real-time GraphQL subscriptions with Absinthe. Covers Phoenix channels, PubSub, and subscription patterns.
act-docker-setupUse when configuring Docker environments for act, selecting runner images, managing container resources, or troubleshooting Docker-related issues with local GitHub Actions testing.
act-local-testingUse when testing GitHub Actions workflows locally with act. Covers act CLI usage, Docker configuration, debugging workflows, and troubleshooting common issues when running workflows on your local machine.
act-workflow-syntaxUse when creating or modifying GitHub Actions workflow files. Provides guidance on workflow syntax, triggers, jobs, steps, and expressions for creating valid GitHub Actions workflows that can be tested locally with act.
ameba-configurationUse when configuring Ameba rules and settings for Crystal projects including .ameba.yml setup, rule management, severity levels, and code quality enforcement.
ameba-custom-rulesUse when creating custom Ameba rules for Crystal code analysis including rule development, AST traversal, issue reporting, and rule testing.
ameba-integrationUse when integrating Ameba into development workflows including CI/CD pipelines, pre-commit hooks, GitHub Actions, and automated code review processes.
analyze-performanceAnalyze performance metrics and identify slow transactions in Sentry