git-worktree

Create, synchronize, and retire Git worktrees in a mirrored directory layout.

2|Updated May 14, 2026
One-click install
npx skills add https://github.com/AnthonyPoschen/agent-skills --skill git-worktree-anthonyposchen
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: git-worktree
Source: https://github.com/AnthonyPoschen/agent-skills/tree/main/skills/git-worktree
Command: npx skills add https://github.com/AnthonyPoschen/agent-skills --skill git-worktree-anthonyposchen

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve? Working on multiple branches in a single checkout forces constant stashing, context switching, and risks mixing unrelated changes. This Skill keeps every branch in its own isolated worktree under a predictable mirrored path, so implementation work never touches the primary checkout. ## Core Features & Use Cases - Predictable mirrored layout: Source checkouts live under ~/git/<provider>/<user>/<repo> and branch worktrees mirror them at ~/worktree/<provider>/<user>/<repo>/<branch-name>, so every checkout is easy to find. - Guarded lifecycle script: The bundled worktree-lifecycle.sh synchronizes clean worktrees with their upstream, removes only merged and clean worktrees, and refuses to touch dirty, detached, or non-mirrored checkouts. - Automated merge cleanup: An opt-in post-merge hook runs the same guarded cleanup after local merges or pulls, removing merged branches without deleting remote branches. - Use Case: You are asked to implement a feature on branch feature/add-search. The Skill derives the target path, creates the worktree from the source checkout, verifies the branch and status, and performs all edits there while the primary checkout stays untouched. ## Quick Start Ask the agent to implement the requested change in a new worktree for a named branch and it will create, verify, and work inside the mirrored checkout.

Frequently Asked Questions about git-worktree

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I create a Git worktree for a new feature branch?▼

Run git worktree add -b <branch> <target-path> from the source checkout to create a new branch in its own worktree. This Skill derives the target path by mirroring the source path under ~/worktree and appending the branch name, keeping slashes as path separators.

How do I clean up Git worktrees after branches are merged?▼

Run worktree-lifecycle.sh cleanup-merged --apply from the primary checkout. It fetches the default remote branch, removes only clean mirrored worktrees whose branches are ancestors of that branch, and deletes the merged local branches without touching remote branches.

Can I update a worktree after its branch changed remotely?▼

Yes, run worktree-lifecycle.sh sync <branch> from the primary checkout. It fetches the branch's remote and fast-forwards only a clean worktree; dirty or diverged worktrees are left intact and reported instead of being reset or rebased.

Why does the cleanup script skip some of my worktrees?▼

The script skips worktrees that are dirty, detached, located outside the mirrored ~/worktree layout, or on unmerged branches. This guard prevents accidental loss of uncommitted changes or work that has not been merged into the base branch.

Does the post-merge hook delete remote branches automatically?▼

No, the post-merge hook only runs the guarded local cleanup after a local merge or pull. It removes clean merged worktrees and their local branches but never deletes remote branches, and it refuses to overwrite an existing hook.