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

git-worktree

Skill4 starsChanged 3 months agoMITView on GitHub

Create a git worktree for isolated branch work by symlinking node_modules and .env files from the main repo — no reinstall. Use when asked to "create a worktree", "add worktree", "work on a branch without reinstalling", "set up worktree for branch". Never run npm/yarn/pnpm install inside the worktree unless package.json changed on the branch.

  • Reads credentials
  • Installs packages

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

We split this skill into the rules it gives an agent

4 rules. 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 25 edited versions we read keep these.

  • 1

    Distinctive

    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. Very specific:

    Create worktrees that reuse the main repo's installed packages via symlinks.

    line 8
  2. Distinctive:

    Run from inside the main repo directory.

    line 12
  3. Very specific:

    Only symlink files that exist in main — the [ -f ...

    line 40
  4. Very specific:

    Remove when done: git worktree remove "../<branch>".

    line 41

“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

Create worktrees that reuse the main repo's installed packages via symlinks. Reinstalling is never needed unless the branch changes package.json.

Steps

Run from inside the main repo directory. The main repo's directory name is resolved dynamically — no hardcoded repo name:

BRANCH=$1
MAIN="$(basename "$(git rev-parse --show-toplevel)")"   # the main repo's dir name
git fetch origin
# Resolve the remote's default branch (main, master, …) — don't hardcode "main".
BASE="$(git symbolic-ref --quiet --short refs/remotes/origin/HEAD 2>/dev/null)"
[ -n "$BASE" ] || { git rev-parse --verify --quiet origin/main >/dev/null \
  && BASE=origin/main || BASE=origin/master; }
# Create the worktree directly ON the branch — never check out afterwards (that
# would detach HEAD and abandon $BRANCH).
if git show-ref --verify --quiet "refs/heads/$BRANCH"; then
  git worktree add "../$BRANCH" "$BRANCH"                 # existing local branch
else
  git worktree add -b "$BRANCH" "../$BRANCH" "$BASE"      # new branch off the default
fi
cd "../$BRANCH"
ln -snf "../$MAIN/node_modules" .
ln -snf "../$MAIN/.env" .
[ -f "../$MAIN/.env.prod" ] && ln -snf "../$MAIN/.env.prod" .   # only if it exists

The worktree is now checked out on $BRANCH (a new branch off the remote's default branch, or the existing one). The symlinks are relative to the worktree dir, so ../$MAIN/ resolves to the sibling main-repo checkout the worktree was created next to.

Rules

  • Never run npm install / yarn / pnpm install inside the worktree unless package.json differs from main.
  • Only symlink files that exist in main — the [ -f ... ] guard skips a missing .env.prod.
  • Remove when done: git worktree remove "../<branch>".

Verify

MAIN="$(basename "$(git rev-parse --show-toplevel)")"
ls -la node_modules .env
# node_modules -> ../<MAIN>/node_modules
# .env -> ../<MAIN>/.env

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.