git-worktree-runner

Manages git worktrees using git-worktree-runner (gtr). Use when the user needs to create, list, remove, or navigate worktrees with `git gtr` commands, open editors or AI tools in worktrees, manage parallel development branches, or check out GitHub PRs (including from forks) into worktrees.

986 stars

Best use case

git-worktree-runner is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Manages git worktrees using git-worktree-runner (gtr). Use when the user needs to create, list, remove, or navigate worktrees with `git gtr` commands, open editors or AI tools in worktrees, manage parallel development branches, or check out GitHub PRs (including from forks) into worktrees.

Teams using git-worktree-runner should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/git-worktree-runner/SKILL.md --create-dirs "https://raw.githubusercontent.com/dyoshikawa/rulesync/main/.rulesync/skills/git-worktree-runner/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/git-worktree-runner/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How git-worktree-runner Compares

Feature / Agentgit-worktree-runnerStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Manages git worktrees using git-worktree-runner (gtr). Use when the user needs to create, list, remove, or navigate worktrees with `git gtr` commands, open editors or AI tools in worktrees, manage parallel development branches, or check out GitHub PRs (including from forks) into worktrees.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Git Worktree Runner (gtr)

git-worktree-runner (gtr) is a CLI tool that wraps `git worktree` with quality-of-life features for modern development workflows including editor and AI tool integration.

## Quick Start

```bash
# Create a new worktree
git gtr new feature-branch

# Create from a remote branch
git gtr new my-branch --from origin/feature-branch

# Open editor in the worktree
git gtr editor feature-branch

# Start AI tool (claude, codex, etc.) in the worktree
git gtr ai feature-branch

# Remove a worktree
git gtr rm feature-branch
```

## Commands

### Creating Worktrees

```bash
# Create a new worktree with a new branch
git gtr new feature-name

# Create from a specific ref (remote branch, tag, commit)
git gtr new my-branch --from origin/main
git gtr new hotfix --from v1.2.3

# Create and immediately open in editor
git gtr new feature -e

# Create and immediately start AI tool
git gtr new feature -a

# Create with both editor and AI tool
git gtr new feature -e -a
```

### Opening Editor / AI Tool

```bash
# Open the configured editor for a worktree
git gtr editor feature-branch

# Start configured AI tool in a worktree
git gtr ai feature-branch
```

### Running Commands

```bash
# Run an arbitrary command in a worktree
git gtr run feature-branch npm test
git gtr run feature-branch pnpm build
```

### Navigation

```bash
# Navigate to a worktree directory
cd "$(git gtr go feature-branch)"
```

### Listing and Managing

```bash
# List all worktrees
git gtr list

# Remove a worktree
git gtr rm feature-branch

# Rename a worktree
git gtr mv old-name new-name
```

## Configuration

```bash
# Set default editor (cursor, vscode, zed, etc.)
git gtr config set gtr.editor.default cursor

# Set default AI tool (claude, codex, opencode, aider, etc.)
git gtr config set gtr.ai.default claude

# Configure files to copy into new worktrees
git gtr config add gtr.copy.include "**/.env"
git gtr config add gtr.copy.include "**/.env.local"
git gtr config add gtr.copy.include "**/.env.example"

# View current configuration
git gtr config list
```

## Example: Parallel AI Development

```bash
# Create isolated worktrees for parallel AI agents
git gtr new feature-auth --from origin/main
git gtr new feature-api --from origin/main
git gtr new bugfix-login --from origin/main

# Start AI tools in each worktree
git gtr ai feature-auth
git gtr ai feature-api
git gtr ai bugfix-login

# Check status of all worktrees
git gtr list

# Clean up when done
git gtr rm feature-auth
git gtr rm feature-api
git gtr rm bugfix-login
```

## Example: PR Review in Isolated Worktree

```bash
# Create a worktree from PR branch
git gtr new review-pr-123 --from origin/pr-branch

# Open in editor to review
git gtr editor review-pr-123

# Run tests in isolation
git gtr run review-pr-123 pnpm test

# Clean up after review
git gtr rm review-pr-123
```

## Example: Hotfix While Working on Feature

```bash
# Current work is on feature-branch, need to do a hotfix
git gtr new hotfix-critical --from origin/main

# Open editor for the hotfix
git gtr new hotfix-critical -e

# After hotfix is done, remove the worktree
git gtr rm hotfix-critical
# Back to feature-branch work without context switching
```

## Example: Checkout a Fork PR into Worktree

For PRs from forked repositories, the branch is not on `origin`. Use GitHub's `refs/pull/<number>/head` ref to fetch it.

### Procedure

Given a PR number or URL:

1. **Get PR metadata**

   ```bash
   gh pr view <PR_NUMBER> --json headRefName,isCrossRepository
   ```

2. **Check for existing worktree** with the same branch name

   ```bash
   git worktree list
   ```

   If it exists, remove it first: `git gtr rm <branch>`

3. **Fetch the PR ref** into a local branch (use `--force` to handle diverged history from force-pushes)

   ```bash
   git fetch origin pull/<PR_NUMBER>/head:<BRANCH_NAME> --force
   ```

4. **Create the worktree** with `--track local` since it's a local-only branch

   ```bash
   git gtr new <BRANCH_NAME> --track local
   ```

5. **Verify**
   ```bash
   git gtr list
   ```

### Full example (PR #1223 from a fork)

```bash
gh pr view 1223 --json headRefName,isCrossRepository
git fetch origin pull/1223/head:fix/comprehensive-file-formats-docs --force
git gtr new fix/comprehensive-file-formats-docs --track local
git gtr list
```

### Shortening long branch names

```bash
git fetch origin pull/1223/head:pr-1223 --force
git gtr new pr-1223 --track local
```

### Common errors

- **"refusing to fetch into branch checked out at..."**: A worktree with that branch exists. `git gtr rm <branch>` first.
- **"non-fast-forward" rejected**: Local branch diverged. Add `--force` to the fetch.
- **Both errors**: Remove the worktree first, then fetch with `--force`.

Related Skills

clean-worktrees

971
from dyoshikawa/rulesync

Clean git worktrees created by git-worktree-runner

rulesync

986
from dyoshikawa/rulesync

Generates and syncs AI rule configuration files (.cursorrules, CLAUDE.md, copilot-instructions.md) across 20+ coding tools from a single source. Use when syncing AI rules, running rulesync commands, importing or generating rule files, or managing shared AI coding configurations.

skill-creator

986
from dyoshikawa/rulesync

Guide for creating effective skills. This skill should be used when users want to create a new skill (or update an existing skill) that extends Claude's capabilities with specialized knowledge, workflows, or tool integrations.

security-scan-diff

986
from dyoshikawa/rulesync

Scan for malicious code in git diff between a tag/commit and HEAD

release-dry-run

986
from dyoshikawa/rulesync

Dry run for release: summarize changes since last release and suggest version bump.

playwright-cli

986
from dyoshikawa/rulesync

Automates browser interactions for web testing, form filling, screenshots, and data extraction. Use when the user needs to navigate websites, interact with web pages, fill forms, take screenshots, test web applications, or extract information from web pages.

draft-release

986
from dyoshikawa/rulesync

Draft a new release of the project.

create-scrap-issue

986
from dyoshikawa/rulesync

Create a GitHub issue that consolidates passed content into a single scrap issue with background context and solution details, labeled as maintainer-scrap. Use when the user wants to create a scrap issue, jot down notes as a GitHub issue, or save findings for later.

create-issue

986
from dyoshikawa/rulesync

Create a GitHub issue with detailed description, purpose, and appropriate labels

review-pr

971
from dyoshikawa/rulesync

Review a pull request for code quality and security issues. Use when the user wants to review a PR, check PR code changes, or audit a pull request. Triggers on: "review PR", "review pull request", "check this PR", "/review-pr".

review-and-comments

971
from dyoshikawa/rulesync

Review a PR for code quality and security issues, then post review comments on it. Runs review-pr followed by post-review-comments sequentially.

rebase-latest-main

971
from dyoshikawa/rulesync

Fetch latest origin/main and rebase it onto the current branch, resolving conflicts if necessary. Use when the user wants to rebase on main, update their branch with latest main, or sync with upstream.