agentleFS
tsubakimototsubakimoto/skills/git-worktree/SKILL.md

git-worktree

Skill2 starsChanged 8 months agoMITView on GitHub

Safely guide Git worktree workflows: creating a separate checkout for a branch or task, listing active worktrees, moving, locking, unlocking, removing, repairing, or pruning worktrees, and resolving errors caused by a branch already being checked out elsewhere. Use this skill whenever a user mentions `git worktree`, parallel Git checkouts, working on multiple branches at once, a worktree path that was moved or deleted manually, or wants to clean up a stale worktree. Before proposing a state-changing command, inspect the repository and affected worktrees, preserve Git's safeguards, and make destructive consequences explicit.

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 7 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

18 rules. 0 are common, 11 are distinctive, and 7 are very specific to this project.

  • 0

    Common

    Most of the 25 edited versions we read keep these.

  • 11

    Distinctive

    This author's own choices. Worth a look.

  • 7

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use the current local Git help and the official documentation when command behavior or version support matters:

    line 23
  2. Distinctive:

    Do not state that a Git option is available until it has been checked against the user's Git version when compatibility is relevant.

    line 29
  3. Distinctive:

    Before a state-changing command, inspect:

    line 40
  4. Very specific:

    Use git worktree list --porcelain when a script or reliable parsing is needed.

    line 56
  5. Distinctive:

    Prefer explicit branches and paths.

    line 62
  6. Very specific:

    Use a relative sibling path such as ../project-feature only when the user has confirmed the layout.

    line 78
  7. Very specific:

    Never suggest -B for a new worktree unless the user explicitly intends to reset an existing branch.

    line 83
  8. Very specific:

    Do not add --force merely to bypass an error.

    line 85
  9. Distinctive:

    If a branch is already checked out, list worktrees and use a different branch, remove the old worktree only after checking it is clean, or …

    line 87
  10. Very specific:

    Before remove, check git -C <path> status --short.

    line 90
  11. Very specific:

    Start stale cleanup with git worktree prune --dry-run --verbose.

    line 95
  12. Distinctive:

    Treat paths containing spaces as one shell argument.

    line 98
  13. Distinctive:

    After every mutation, show a concise verification sequence:

    line 102
  14. Distinctive:

    If status is not clean, stop and explain the choices.

    line 152
  15. Distinctive:

    If the primary repository and moved worktree still exist, run from the primary repository:

    line 156
  16. Distinctive:

    If a worktree directory was intentionally deleted manually, preview stale entries first:

    line 163
  17. Distinctive:

    Use this order unless the user asks for only a command:

    line 172
  18. Very specific:

    Keep normal operations concise.

    line 179

“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 Skill

Help users manage multiple working directories from one Git repository without accidentally sharing a branch, deleting uncommitted changes, or removing worktree metadata that Git needs. Git allows one non-detached branch to be checked out by only one worktree at a time; verify this constraint before creating or switching a worktree.

Source of truth

Use the current local Git help and the official documentation when command behavior or version support matters:

Do not state that a Git option is available until it has been checked against the user's Git version when compatibility is relevant.

Workflow

1. Identify the intent and affected paths

Determine whether the user wants to create, inspect, move, lock, unlock, remove, repair, or prune a worktree. Identify the repository, target path, branch, and starting commit. Ask one focused clarification question when any of these would change the command or risk profile.

Before a state-changing command, inspect:

git rev-parse --show-toplevel
git worktree list --porcelain
git branch --show-current
git status --short

For an existing worktree, inspect it explicitly:

git -C <worktree-path> status --short
git -C <worktree-path> branch --show-current

Use git worktree list --porcelain when a script or reliable parsing is needed. It is stable across Git versions and configuration; combine it with -z only when code must safely parse unusual path names.

2. Choose the safest command

Prefer explicit branches and paths. Do not rely on Git inferring a branch name from a directory name when a user needs a predictable checkout.

GoalSafe starting command
New worktree with a new task branchgit worktree add -b <branch> <path> [<start-point>]
Worktree for an existing branch that is not checked out elsewheregit worktree add <path> <branch>
Temporary inspection at a commit without a branchgit worktree add --detach <path> <commit-ish>
See all registrations and their stategit worktree list --verbose
Protect a portable or long-lived worktreegit worktree lock --reason "<reason>" <path>
Allow an intentionally locked worktree to be managedgit worktree unlock <path>
Relocate a registered worktreegit worktree move <worktree> <new-path>
Reconnect metadata after moving/deleting paths manuallygit worktree repair [<path>...]
Preview stale-registration cleanupgit worktree prune --dry-run --verbose
Remove a clean worktreegit worktree remove <path>

Use a relative sibling path such as ../project-feature only when the user has confirmed the layout. Otherwise show the exact absolute or repository-relative path being used.

3. Respect safeguards

  • Never suggest -B for a new worktree unless the user explicitly intends to reset an existing branch; it can discard branch history by resetting it to the chosen start point.
  • Do not add --force merely to bypass an error. Explain which protection Git reported, inspect the affected branch or path, and offer a non-destructive alternative first.
  • If a branch is already checked out, list worktrees and use a different branch, remove the old worktree only after checking it is clean, or make a detached checkout when that serves the user's purpose. Do not force the same branch into two normal worktrees.
  • Before remove, check git -C <path> status --short. An empty result supports ordinary removal; non-empty output means changes need committing, moving, stashing, or explicit destructive confirmation.
  • git worktree remove --force discards an unclean worktree. A locked worktree needs force twice. Only show either form after the user has explicitly accepted that loss or override.
  • Start stale cleanup with git worktree prune --dry-run --verbose; run prune --verbose only after reviewing the preview. Use repair when the on-disk worktree still exists but its registration links are out of date.
  • Treat paths containing spaces as one shell argument. Quote them in shell examples.

4. Verify the result

After every mutation, show a concise verification sequence:

git worktree list --verbose
git -C <worktree-path> status --short
git -C <worktree-path> branch --show-current

For a newly created worktree, also confirm the branch relationship when relevant:

git -C <worktree-path> status --branch --short

Common scenarios

Start a task without leaving the current branch

git fetch origin
git worktree add -b feature/<topic> ../<repository>-<topic> origin/main

Explain the chosen start point and replace origin/main with the repository's actual integration branch when it differs. If the repository does not need a fetch, omit it rather than adding network activity by default.

Work on an existing local branch

First confirm it is not already checked out:

git worktree list --verbose
git branch --show-current

Then use:

git worktree add ../<repository>-<branch> <branch>

Remove a completed worktree

git -C ../<repository>-<topic> status --short
git worktree remove ../<repository>-<topic>
git worktree list --verbose

If status is not clean, stop and explain the choices. Do not silently stash or discard work.

Repair after a manual filesystem move

If the primary repository and moved worktree still exist, run from the primary repository:

git worktree repair <new-worktree-path>
git worktree list --verbose

If a worktree directory was intentionally deleted manually, preview stale entries first:

git worktree prune --dry-run --verbose
git worktree prune --verbose

Response format

Use this order unless the user asks for only a command:

  1. Situation — current worktree/branch state and the goal.
  2. Safe command — the smallest command sequence with placeholders replaced where known.
  3. Before running — branch, path, dirty-state, or destructive-operation caveats that apply.
  4. Verify — command(s) that prove the intended worktree is registered and clean.

Keep normal operations concise. When blocked by Git safeguards, describe the actual conflict and present the safest alternatives rather than treating --force as the default solution.

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.