git-worktrees
git, worktrees, parallel-work, branch-isolation, pr-review, cleanup
- License 许可
- BSD-3-Clause
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- git-worktrees
- description
- git, worktrees, parallel-work, branch-isolation, pr-review, cleanup
- compatibility
- Requires git 2.22+ and Python 3.10+ (stdlib only).
02 资源文件 1
- 脚本scripts/worktree.py8.6 KB
03 SKILL.md 正文
Git worktrees
Goal
Give each branch or pull request its own checked-out directory under one shared root, so parallel work never disturbs the primary checkout.
Input
Run inside a git repository. Supply a branch name or a PR number:
--root DIRoverrides the worktree root; default~/git/worktrees, also configurable withGIT_WORKTREE_ROOT.--base REFcreates a missing branch fromREF; without it a missing branch is an error.--pr Nfetches pull requestNfromorigininto branchpr/N.--dry-runprints the plan without mutating anything.
Output
~/git/worktrees/<project-slug>-<pr-or-branch-name>
<project-slug> comes from the repository directory name; separators in
branch names become -. Branch feature/foo in repository my-app
lands at ~/git/worktrees/my-app-feature-foo; PR 12 lands at
~/git/worktrees/my-app-pr-12. Creating prints the new path.
Workflow
Invoke scripts/worktree.py from this skill with python3:
python3 scripts/worktree.py add feature/foo --base main
python3 scripts/worktree.py add --pr 123
python3 scripts/worktree.py path feature/foo
python3 scripts/worktree.py list
python3 scripts/worktree.py remove my-app-feature-foo
python3 scripts/worktree.py prune
remove accepts a worktree directory name (looked up under the root),
a relative path, or an absolute path.
Rules
- Only create or delete directories under the configured worktree root.
- Fail closed: never overwrite an existing directory, never delete
branches, and never guess between reusing an existing branch and
creating a new one;
--basemust say so explicitly. - Never create a second worktree for a branch already checked out anywhere, and never remove the main working tree.
git worktree removerefuses dirty or locked worktrees; pass--forceonly when the operator confirmed discarding the changes.- Use the printed path as the single source of truth; never hand-build worktree directories outside this layout.
- When work ends,
removethe worktree andprune; keep or delete branches by explicit choice, never as a side effect.
Verification
git worktree list
git -C <worktree-path> status
The new path must appear registered and its status clean. For this
skills repository, also run bash scripts/validate-skills,
bash scripts/validate-support-scripts, and
python3 -m unittest tests/test_git_worktrees.py -v.
04 同仓库更多 Skills
unknown-frontmatter
validator, fixture
zara-phone-pair
zara, phone, pairing, adb, wireless-debugging, curve, enrollment, android
zara-mcp
zara, mcp, stdio, http, tools, resources, prompts, debugging
youtube-context
youtube, transcripts, yt-dlp, whisper, video-context
worker-orchestration
workers, routing, delegation, fleet, budgets, concurrency
task-steward-worker
steward, rage, leases, fencing, heartbeat, receipts