agentleFS
alex-voloshin-devalex-voloshin-dev/ai-skills/.agents/skills/worktree-isolation/SKILL.md

worktree-isolation

Skill2 starsChanged 6 months agoMITView on GitHub

Git worktree branch isolation for feature development and bugfixes — branch naming, worktree setup, branch verification, and safe cleanup. Use when developing features or fixing bugs in isolated branches via git worktree.

9 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. 0 are common, 12 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 8 edited versions we read keep these.

  • 12

    Distinctive

    This author's own choices. Worth a look.

  • 1

    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:

    Keep the description portion under 40 characters

    line 26
  2. Very specific:

    Never use generic names like dev, temp, wip, or my-branch

    line 27
  3. Distinctive:

    If the branch exists locally — use it

    line 49
  4. Distinctive:

    If the branch exists only on remote — fetch and track it

    line 50
  5. Distinctive:

    If the branch does not exist anywhere — create it from the current main branch

    line 51
  6. Distinctive:

    After entering the worktree, always confirm:

    line 71
  7. Distinctive:

    Before every commit, verify the current branch:

    line 83
  8. Distinctive:

    Never switch branches inside the worktree.

    line 93
  9. Distinctive:

    Commit only to the designated branch

    line 97
  10. Distinctive:

    Follow the project's commit message conventions

    line 98
  11. Distinctive:

    Do not merge main into the feature branch inside the worktree — rebase if needed

    line 99
  12. Distinctive:

    After the feature is merged or the work is complete:

    line 103
  13. Distinctive:

    Do not delete the worktree while it has uncommitted changes.

    line 113

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

Worktree Isolation

Procedure for isolating feature and bugfix work on dedicated branches using git worktree. Prevents accidental commits to the wrong branch and keeps the main working tree clean.

Branch Naming

Derive the branch name from the task context. Use the git-conventions branch naming format:

SourceBranch name
Bug ticket with IDfix/<ID>-<short-description> — e.g. fix/BUG-044-null-payment-response
Feature PRDfeature/<feature-name> — use the feature folder name or the title from the PRD, kebab-cased
Feature folderfeature/<folder-name> — match the directory that holds the feature spec
Hotfixhotfix/<ID>-<short-description>
Refactorrefactor/<short-description>

Rules:

  • Always lowercase, hyphen-separated
  • Include the ticket/bug ID when one exists
  • Keep the description portion under 40 characters
  • Never use generic names like dev, temp, wip, or my-branch

Setup Procedure

Execute these steps in order before writing any code:

1. Determine Branch Name

BRANCH_NAME = derive from task context (see table above)

2. Check if Branch Already Exists

# Check local branches
git branch --list "$BRANCH_NAME"

# Check remote branches
git branch -r --list "origin/$BRANCH_NAME"
  • If the branch exists locally — use it
  • If the branch exists only on remote — fetch and track it
  • If the branch does not exist anywhere — create it from the current main branch

3. Create or Enter the Worktree

# If branch does not exist — create worktree with new branch
git worktree add ../worktree-$BRANCH_NAME -b "$BRANCH_NAME"

# If branch already exists locally
git worktree add ../worktree-$BRANCH_NAME "$BRANCH_NAME"

# If branch exists only on remote
git fetch origin "$BRANCH_NAME"
git worktree add ../worktree-$BRANCH_NAME "$BRANCH_NAME"

The worktree path sits alongside the main repo directory. Adjust the path if the environment requires a different location.

4. Verify Branch

After entering the worktree, always confirm:

git branch --show-current

Hard rule: the output MUST match $BRANCH_NAME. If it does not — stop and fix before writing any code. Do not proceed on the wrong branch.

During Development

Branch Guard

Before every commit, verify the current branch:

current=$(git branch --show-current)
if [ "$current" != "$BRANCH_NAME" ]; then
  echo "ERROR: on branch '$current', expected '$BRANCH_NAME'" >&2
  exit 1
fi

Never switch branches inside the worktree. The worktree is locked to its branch. If you need a different branch, create a separate worktree.

Commit Rules

  • Commit only to the designated branch
  • Follow the project's commit message conventions
  • Do not merge main into the feature branch inside the worktree — rebase if needed

Cleanup

After the feature is merged or the work is complete:

# From the main working tree (not from inside the worktree)
git worktree remove ../worktree-$BRANCH_NAME

# If the branch was merged, delete it
git branch -d "$BRANCH_NAME"

Do not delete the worktree while it has uncommitted changes. Commit or stash first.

Error Recovery

ProblemAction
Worktree path already existsCheck if it belongs to this branch. If yes, reuse. If stale, run git worktree prune then retry
Branch exists but worktree does notCreate worktree pointing to the existing branch
Detached HEAD in worktreeRun git checkout "$BRANCH_NAME" inside the worktree
Worktree lockedRun git worktree unlock ../worktree-$BRANCH_NAME then retry

Integration

  • Used by: feature-dev skill, bugfix skill
  • Follows: git-conventions rule (branch naming, commit messages)

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.