agentleFS
kyto64kyto64/aidd-template-scale/.cursor/rules/git-worktree.mdc

aidd-template-scale / rules

Cursor rule0 starsChanged 2 months agoMITView on GitHub

Git worktree workflow

The file

We split this git-worktree.mdc into the rules it gives an agent

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    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
  1. Distinctive:

    When starting ticket work:

    line 11
  2. Distinctive:

    NEVER: run git checkout -b, git switch -c, or equivalent on the main repository working tree.

    line 13
  3. Very specific:

    ALWAYS: create a worktree with git worktree add -b <branch> <worktrees-dir>/<dir> origin/main.

    line 14
  4. Distinctive:

    Do not use git rev-parse --show-toplevel alone (inside an existing worktree it returns the worktree path).

    line 19
  5. Distinctive:

    Use the main repo root:

    line 21
  6. Very specific:

    If pwd is under ${WORKTREES_ROOT}/ → OK, continue.

    line 40
  7. Very specific:

    If pwd is the main repo root and you are starting ticket implementation → STOP, create worktree first.

    line 41
  8. Distinctive:

    Remove the worktree when the branch is merged and no longer needed:

    line 59

≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “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
git-worktree.mdc
---
alwaysApply: true
description: Git worktree workflow
globs: **/*
---

# Git worktree workflow

## Rules (NEVER / ALWAYS)

When starting ticket work:

- **NEVER** run `git checkout -b`, `git switch -c`, or equivalent on the **main repository working tree**.
- **ALWAYS** create a worktree with `git worktree add -b <branch> <worktrees-dir>/<dir> origin/main`.
- **ALWAYS** `cd` into that worktree before Edit / Write / Bash for implementation.

## Resolve main repository root

Do **not** use `git rev-parse --show-toplevel` alone (inside an existing worktree it returns the worktree path).

Use the main repo root:

```bash
COMMON=$(git rev-parse --git-common-dir)
MAIN_ROOT=$(cd "$COMMON/.." && pwd)
REPO=$(basename "$MAIN_ROOT")
WORKTREES_ROOT="$(dirname "$MAIN_ROOT")/${REPO}-worktrees"
```

Worktrees live at: `${WORKTREES_ROOT}/<dir>/`

## Preflight (before first edit)

```bash
git rev-parse --git-common-dir
pwd
git worktree list
```

- If `pwd` is under `${WORKTREES_ROOT}/` → OK, continue.
- If `pwd` is the main repo root and you are starting ticket implementation → **STOP**, create worktree first.

## Create worktree

```bash
ISSUE=42
BRANCH="feature/${ISSUE}"
DIR=$(echo "$BRANCH" | tr '/' '-')
mkdir -p "$WORKTREES_ROOT"
git fetch origin
git worktree add -b "$BRANCH" "${WORKTREES_ROOT}/${DIR}" origin/main
cd "${WORKTREES_ROOT}/${DIR}"
```

Reuse an existing worktree/branch if one already exists for the same issue.

## After merge

Remove the worktree when the branch is merged and no longer needed:

```bash
git worktree remove "${WORKTREES_ROOT}/${DIR}"
git branch -d "$BRANCH"
```

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.