using-git-worktrees

Creates isolated git worktrees outside the repository with auto-commit detection and leak verification gates.

Updated Nov 1, 2024
One-click install
npx skills add https://github.com/mlorentedev/dotfiles --skill using-git-worktrees-mlorentedev
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: using-git-worktrees
Source: https://github.com/mlorentedev/dotfiles/tree/main/harness/skills/using-git-worktrees
Command: npx skills add https://github.com/mlorentedev/dotfiles --skill using-git-worktrees-mlorentedev

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Parallel feature work often requires switching branches or cloning the repository again, and worktrees created inside a repo can be silently committed as gitlinks by auto-committing tools like obsidian-git. This Skill sets up isolated git worktrees with deterministic safety gates that prevent workspace leaks and repository corruption. ## Core Features & Use Cases - External worktree placement: Defaults to a sibling directory (<repo>-wt-<slug>) outside the repository working tree, so no ignore rule is ever needed for isolation. - Safety gates: Gate A detects auto-commit tooling (obsidian-git, hooks, autocommit configs) before creation; Gate B audits parent status and 160000 gitlinks after creation to catch leaks before work begins. - Auto-detected project setup: Runs the right bootstrap (npm install, cargo build, pip install, poetry install, go mod download) based on project files, then verifies a clean test baseline. - Use Case: Before executing an implementation plan, ask the assistant to spin up an isolated worktree; it creates myrepo-wt-feature-x on a new branch, installs dependencies, confirms no gitlink leaks, and reports ready. ## Quick Start Ask the assistant to use the using-git-worktrees skill to create an isolated worktree for your next feature branch before starting implementation.

Frequently Asked Questions about using-git-worktrees

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

FAQPage Schema
How do I create a git worktree for parallel feature development?

Run `git worktree add <path> -b <branch>` with the path placed outside the repository, such as a sibling directory named `<repo>-wt-<slug>`. Then install dependencies based on detected project files and verify a clean test baseline before starting work.

Why should git worktrees be placed outside the repository?

A nested worktree contains a `.git` file, so any tool running `git add -A` stages it as a `160000` gitlink, embedding it into the parent branch like a submodule. External placement makes isolation physical and independent of any ignore rule.

Can I use git worktrees with Obsidian vaults or auto-commit repos?

Yes, but external placement is mandatory. Auto-committing tools like obsidian-git can commit a nested worktree as a gitlink before any `.gitignore` rule takes effect, so the worktree must live outside the repository working tree.

How do I check if a worktree leaked into the parent repository?

Run `git status --porcelain` in the parent repo and confirm the worktree name does not appear, then audit `git ls-files --stage` for entries with mode `160000`. Any match means the worktree is embedded and must be moved out.

How do I remove a git worktree when work is finished?

Run `git worktree remove <path>`, adding `--force` only when intentionally discarding changes. Then re-audit for `160000` gitlinks in the parent index and run `git worktree prune` to clean stale metadata.