agentleFS
AnthonyPoschenAnthonyPoschen/agent-skills/skills/git-worktree/SKILL.md

git-worktree

Skill2 starsChanged 3 months agoMITView on GitHub

Create, synchronize, and safely retire isolated Git worktrees for implementation work. Use whenever the user asks to work in a worktree, isolate a change on a branch, create a feature checkout, update a worktree after branch changes, or clean up merged worktrees, or says "make sure its in a worktree", "/implement in a worktree", or "in a new worktree / branch". Clone or fork into `~/git/<provider>/<user>/<repo>` (a normal `git clone` already follows `~/git/github.com/anthonyposchen/<repo>`); do not `gh repo fork --clone` into the current directory. New worktrees mirror a source checkout below ~/git at ~/worktree/<provider>/<user>/<repo>/<branch-name>.

27 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use caveman, triage and 4 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.
  • MicrosoftSkill

    caveman

    Ultra-compressed response style that reduces output token count while preserving technical accuracy, with intensity levels and auto-clarity safety rules

    Also in 3 projects that use this

  • Google CloudSkill

    triage

    Gather context on a change or bug and plan the implementation.

    Also in 3 projects that use this

  • AWSSkill

    grill-me

    A relentless interview to sharpen a plan or design.

    Also in 4 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

  • AWSSkill

    tdd

    Test-driven development. Use when the user wants to build features or fix bugs test-first, mentions "red-green-refactor", or wants integration tests.

    Also in 3 projects that use this

  • GoogleSkill

    code-review

    Adversarial systems, concurrency, memory-model, and architecture code review protocol. Use this skill whenever asked to review code, PRs, diffs, or branches in Filament.

    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

13 rules. 0 are common, 8 are distinctive, and 5 are very specific to this project.

  • 0

    Common

    Most of the 22 edited versions we read keep these.

  • 8

    Distinctive

    This author's own choices. Worth a look.

  • 5

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Keep implementation changes isolated from the primary checkout while making every checkout easy to find.

    line 10
  2. Very specific:

    Keep slashes in a branch name as path separators.

    line 23
  3. Distinctive:

    If already inside a linked worktree, check that its path equals the derived target and that it is on the intended branch.

    line 40
  4. Very specific:

    Create the target's parent directories, then create the worktree from the source checkout: use git worktree add -b <branch> <target> for a …

    line 48
  5. Distinctive:

    Treat a worktree as the checkout for one branch for its full lifetime.

    line 60
  6. Distinctive:

    Create or resume the worktree before editing it.

    line 62
  7. Distinctive:

    When you learn that its branch changed remotely, was rebased, or received review changes, synchronize it before doing more work.

    line 63
  8. Distinctive:

    When a branch is known to be merged, run the guarded cleanup immediately from the primary checkout:

    line 75
  9. Very specific:

    When the user abandons an unmerged branch, remove its clean checkout from the primary checkout with worktree-lifecycle.sh remove …

    line 85
  10. Distinctive:

    After a worktree directory was manually removed or a filesystem restore, inspect with git worktree list and run git worktree prune only …

    line 89
  11. Very specific:

    Run worktree-lifecycle.sh cleanup-merged without --apply to preview every candidate.

    line 93
  12. Very specific:

    When the user asks for automatic cleanup, run worktree-lifecycle.sh install-post-merge-hook from the primary checkout.

    line 99
  13. Distinctive:

    Do not create a worktree for the primary branch when it is already checked out in the primary checkout.

    line 112

“Common” is measured: kept by at least 6 in 10 of the 22 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

Goal

Keep implementation changes isolated from the primary checkout while making every checkout easy to find. A source repository at:

~/git/<provider>/<user>/<repo>

has branch worktrees at:

~/worktree/<provider>/<user>/<repo>/<branch-name>

Keep slashes in a branch name as path separators. For example, feature/add-search belongs at ~/worktree/github/acme/widgets/feature/add-search.

Workflow

  1. Confirm the current directory belongs to a Git working tree with git rev-parse --show-toplevel. Resolve its canonical path.
  2. Find the primary checkout with git worktree list --porcelain. Its path must be below ~/git/; otherwise stop and ask for a source checkout or an explicitly approved path. Do not guess a different storage layout.
  3. Choose the branch named by the user. If none is named, derive a concise, descriptive branch name from the requested work and state it before creating the worktree. Validate it with git check-ref-format --branch.
  4. Derive the relative source path below ~/git/, then construct the exact target path below ~/worktree/ by appending the branch name. Do not shorten, flatten, hash, or otherwise change either part of the path.
  5. If already inside a linked worktree, check that its path equals the derived target and that it is on the intended branch. Continue there only when both match. If it is an older worktree at another path, leave it untouched and ask before changing location.
  6. Inspect git worktree list --porcelain before creating anything. If the target already exists and is registered, resume it. If the branch is already checked out elsewhere, do not force it into another worktree; resume that checkout when it matches the required target or ask for a different branch.
  7. Create the target's parent directories, then create the worktree from the source checkout: use git worktree add -b <branch> <target> for a new branch, or git worktree add <target> <branch> for an existing unoccupied branch. Base a new branch on the source checkout's current HEAD unless the user specifies another base.
  8. Change into the target and verify git rev-parse --show-toplevel, git branch --show-current, and git status --short. Perform all requested edits, tests, and commits from this worktree. Never edit the primary checkout as part of this workflow.

Manage the lifecycle

Treat a worktree as the checkout for one branch for its full lifetime.

  1. Create or resume the worktree before editing it.
  2. When you learn that its branch changed remotely, was rebased, or received review changes, synchronize it before doing more work. From the primary checkout, run this Bash helper:

    <skill-path>/scripts/worktree-lifecycle.sh sync <branch-name>

    The command fetches the branch's remote, then fast-forwards only a clean worktree. If the worktree has local changes or diverged history, leave it intact and report the condition instead of stashing, resetting, rebasing, or forcing an update.

  3. When a branch is known to be merged, run the guarded cleanup immediately from the primary checkout:

    <skill-path>/scripts/worktree-lifecycle.sh cleanup-merged --apply

    It fetches the default remote branch, removes only clean mirrored worktrees whose branches are ancestors of that branch, and then deletes their merged local branches. It never deletes remote branches.

  4. When the user abandons an unmerged branch, remove its clean checkout from the primary checkout with worktree-lifecycle.sh remove <branch-name>. Keep the branch unless the user explicitly asks to delete it.
  5. After a worktree directory was manually removed or a filesystem restore, inspect with git worktree list and run git worktree prune only when the stale entries are understood.

Run worktree-lifecycle.sh cleanup-merged without --apply to preview every candidate. Report skipped dirty, detached, non-mirrored, and unmerged worktrees so the user can decide their fate.

Automate local merge cleanup

When the user asks for automatic cleanup, run worktree-lifecycle.sh install-post-merge-hook from the primary checkout. The opt-in hook runs the same guarded merged-branch cleanup after a local merge or pull. It refuses to overwrite another hook. It needs Bash and Git.

Hosted Git providers cannot run a command on this machine when a pull request is merged remotely. When an agent learns about that merge, it must run the cleanup step above; the fetch in that command makes remote merges visible locally.

Safety

  • Preserve existing worktrees, branches, and uncommitted changes. Do not use --force, remove a worktree, prune metadata, reset, or clean as setup.
  • Do not create a worktree for the primary branch when it is already checked out in the primary checkout. Choose a task branch instead.
  • Report the branch and absolute worktree path before beginning the requested implementation. Cleanup after a known merge is part of this lifecycle; all other cleanup requires an explicit user request.

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.