agentleFS
yht-4403yht-4403/jc-agent-skills/git-worktree/SKILL.md

git-worktree

Skill1 starsChanged 15 days agoMITView on GitHub

Git worktree management skill for parallel development with Claude Code. Use when you need to: (1) Create a new worktree for parallel task development, (2) List all active worktrees, (3) Merge a worktree branch back to main using rebase + ff-only strategy, (4) Clean up completed worktrees. Maintains linear git history with rebase workflow.

  • Commits and pushes

30 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use agent-native-architecture, document-review and 6 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • CodeWithBehnamSkill

    agent-native-architecture

    Build applications where agents are first-class citizens. Use this skill when designing autonomous agents, creating MCP tools, implementing self-modifying systems, or building apps where features are outcomes achieved by agents operating in a loop.

    Also in 3 projects that use this

  • CodeWithBehnamSkill

    document-review

    This skill should be used to refine brainstorm or plan documents before proceeding to the next workflow step. It applies when a brainstorm or plan document exists and the user wants to improve it.

    Also in 3 projects that use this

  • MicrosoftSkill

    git-commit

    Stage user-selected paths, confirm the exact staged set, and create one local Conventional Commit, or generate a commit message for staged changes without committing. Use when you want a guarded commit or a ready-to-paste message.

    Also in 3 projects that use this

  • MicrosoftSkill

    grill-with-docs

    Grilling session that challenges your plan against the existing domain model, sharpens terminology, and updates documentation (CONTEXT.md, ADRs) inline as decisions crystallise. Use when user wants to stress-test a plan against their project's language and documented decisions.

    Also in 3 projects that use this

  • OpenAISkill

    brainstorming

    You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

    Also in 3 projects that use this

  • BlockSkill

    frontend-design

    Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

    Also in 4 projects that use this

The file

Show its rules and text

We split this skill into the rules it gives an agent

22 rules. 0 are common, 19 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 25 edited versions we read keep these.

  • 19

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Distinctive:

    When the user invokes this skill, ask them which operation they want:

    line 17
  2. Distinctive:

    create: - Create a new worktree for a task

    line 19
  3. Distinctive:

    cleanup: - Remove a completed worktree

    line 22
  4. Distinctive:

    Create a new worktree for parallel development.

    line 28
  5. Distinctive:

    Ask the user for:

    line 32
  6. Distinctive:

    Create worktree as a sibling directory:

    line 49
  7. Very specific:

    Always base new worktrees on origin/main (latest remote main)

    line 71
  8. Distinctive:

    Never create a worktree on a branch that already has one (check with git worktree list)

    line 72
  9. Distinctive:

    Ask which branch to merge (show list from git worktree list)

    line 112
  10. Distinctive:

    If dirty, warn the user and ask whether to proceed.

    line 119
  11. Distinctive:

    After successful merge, ask if user wants to cleanup the worktree.

    line 154
  12. Very specific:

    ALWAYS use --ff-only for the final merge to main - never create merge commits

    line 157
  13. Very specific:

    ONLY use --force-with-lease (never --force) and only on feature branches that were rebased

    line 158
  14. Distinctive:

    NEVER force push to main

    line 159
  15. Distinctive:

    If rebase has conflicts, stop and help the user resolve them before continuing

    line 160
  16. Distinctive:

    Always git fetch origin before any merge operation

    line 161
  17. Distinctive:

    Remove a completed worktree.

    line 167
  18. Distinctive:

    Check if the branch has been merged:

    line 173
  19. Distinctive:

    If NOT merged, warn the user:

    line 178
  20. Distinctive:

    Never rebase main: - only rebase feature/bugfix branches

    line 211
  21. Distinctive:

    Always fetch before merge: - ensure you have the latest remote state

    line 212
  22. Distinctive:

    One branch per worktree: - never checkout a different branch in an existing worktree

    line 213

“Common” is measured: kept by at least 6 in 10 of the 25 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Git Worktree - Parallel Development with Claude Code

Overview

This skill helps you manage Git worktrees for parallel development. Each worktree is an independent working directory with its own branch, allowing multiple Claude Code sessions to work simultaneously on different tasks.

Core principle: rebase to align, ff-only to merge, linear history always.

Usage

When the user invokes this skill, ask them which operation they want:

  1. create - Create a new worktree for a task
  2. list - Show all active worktrees and their status
  3. merge - Merge a worktree branch back to main
  4. cleanup - Remove a completed worktree

Operation: create

Create a new worktree for parallel development.

Steps

  1. Ask the user for:
    • Task description (used to generate branch name)
    • Branch type: feature/, bugfix/, or hotfix/
  2. Get the project root directory:
PROJECT_ROOT=$(git rev-parse --show-toplevel)
PROJECT_NAME=$(basename "$PROJECT_ROOT")
  1. Fetch latest remote:
git fetch origin
  1. Generate branch name from task description (lowercase, hyphens, no special chars). For example, task "add interview scoring" becomes feature/interview-scoring.
  2. Create worktree as a sibling directory:
# Pattern: ../{project-name}-{short-branch-suffix}
git worktree add "../${PROJECT_NAME}-${BRANCH_SUFFIX}" -b "${BRANCH_TYPE}/${BRANCH_NAME}" origin/main
  1. Confirm creation and print instructions:
Worktree created:
  Path:   /Users/cv-project/jobprep-ai-{suffix}
  Branch: feature/xxx

To start a parallel Claude Code session:
  1. Open a new terminal
  2. cd /Users/cv-project/jobprep-ai-{suffix}
  3. Run: claude
  4. Start working on your task

Current worktree stays unaffected.

Important rules for create

  • Always base new worktrees on origin/main (latest remote main)
  • Never create a worktree on a branch that already has one (check with git worktree list)
  • Worktree directory is always a sibling of the project root, never nested inside

Operation: list

Show all active worktrees with their status.

Steps

  1. Run:
git worktree list
  1. For each worktree, show:
# For each branch in worktree list
git log --oneline -1 <branch>
git log --oneline main..<branch> | wc -l  # commits ahead
git status --short --porcelain             # uncommitted changes
  1. Format output as a table:
| # | Path                            | Branch              | Commits ahead | Uncommitted |
|---|--------------------------------|---------------------|---------------|-------------|
| 1 | /Users/cv-project/jobprep-ai-main    | bugfix/production   | 23            | 4 files     |
| 2 | /Users/cv-project/jobprep-feature    | feature/interview   | 3             | clean       |

Operation: merge

Merge a worktree branch back to main, maintaining linear history.

Steps

  1. Ask which branch to merge (show list from git worktree list)
  2. Pre-merge checks:
# Check for uncommitted changes in that worktree
git -C <worktree-path> status --porcelain

If dirty, warn the user and ask whether to proceed.

  1. Determine merge strategy:
# Check if main has advanced since branch was created
git fetch origin
git log --oneline origin/main..<branch> | wc -l   # branch commits
git log --oneline <branch>..origin/main | wc -l    # main commits since branch

4a. If main has NO new commits (fast-forward possible):

git checkout main
git pull origin main
git merge <branch> --ff-only
git push origin main

4b. If main HAS new commits (need rebase first):

# Rebase the branch onto latest main
git -C <worktree-path> fetch origin
git -C <worktree-path> rebase origin/main

# If conflicts, notify user and help resolve
# After rebase, force-push the branch (only if previously pushed)
git -C <worktree-path> push origin <branch> --force-with-lease

# Then ff-only merge
git checkout main
git pull origin main
git merge <branch> --ff-only
git push origin main
  1. After successful merge, ask if user wants to cleanup the worktree.

Important rules for merge

  • ALWAYS use --ff-only for the final merge to main - never create merge commits
  • ONLY use --force-with-lease (never --force) and only on feature branches that were rebased
  • NEVER force push to main
  • If rebase has conflicts, stop and help the user resolve them before continuing
  • Always git fetch origin before any merge operation

Operation: cleanup

Remove a completed worktree.

Steps

  1. Show worktree list, ask which to remove
  2. Check if the branch has been merged:
git branch --merged main | grep <branch>
  1. If NOT merged, warn the user:
Warning: branch <branch> has NOT been merged to main.
Removing this worktree will NOT delete the branch, but the working directory will be gone.
Continue? (y/n)
  1. Remove:
git worktree remove <worktree-path>
# If branch was merged, also delete the branch
git branch -d <branch>
  1. Confirm cleanup complete.

Commit conventions

Commits in worktrees follow the same conventions as the main project. No special handling needed - each worktree is a normal git working directory.

# In any worktree, commits work normally:
git add .
git commit -m "feat: description"
git push origin <branch>

Safety rules

  1. Never force push to main - main is protected, always ff-only
  2. Never delete a worktree with uncommitted changes without explicit user confirmation
  3. Never rebase main - only rebase feature/bugfix branches
  4. Always fetch before merge - ensure you have the latest remote state
  5. One branch per worktree - never checkout a different branch in an existing worktree

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.