Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计提醒

git-worktreeGit 工作树

Agent Skill

git-worktree 用于查找、检索和筛选相关信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要根据关键词、任务场景或来源线索快速定位候选结果时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

196

周安装

8

GitHub Stars

公开资料未说明

下载量

63
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:git-worktree(Git 工作树)
来源仓库:https://github.com/bar2133/skills
仓库路径:skills/git-worktree
安装命令:
npx skills add https://github.com/bar2133/skills --skill git-worktree
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/bar2133/skills --skill git-worktree

简介

git-worktree 用于创建和管理 Git 工作树,支持在单一仓库或多仓库环境中隔离功能开发与问题修复。

  • 适合在 Codex、Claude、Cursor、Gemini CLI 中需要为特定任务建立独立开发环境时使用。
  • 通过统一流程自动发现仓库、选择分支、创建工作目录并完成项目初始化。
  • 安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。
  • 适用宿主包括 Codex、Claude、Cursor、Gemini CLI,接入前应确认版本、权限和运行环境要求。

SKILL.md

Git Worktree

Create and manage git worktrees for isolated feature and bugfix work. Works seamlessly with single-repo workspaces and flat multi-repo workspaces (a parent folder containing multiple independent git repos side by side).

Announce at start: "I'm using the git-worktree skill to set up an isolated workspace."

Unified Flow

The same pipeline handles 1 repo or N repos:

  1. Discover repos
  2. Select repos (if multiple)
  3. Ask purpose and suggest branch names
  4. Ask worktree location
  5. Create worktrees and copy.env files
  6. Run project setup
  7. Report summary

1. Discover Repos

Detect all git repos in the current workspace. Use two strategies and combine results:

# Strategy 1: Scan current directory and immediate children for .git directories
# This works whether you're in a repo, a parent of repos, or anywhere
find . -maxdepth 2 -name .git -type d 2>/dev/null | sed 's|/.git$||'

# Strategy 2: If currently inside a git repo, also include it
# (handles the case where cwd is deep inside a single repo)
git_root=$(git rev-parse --show-toplevel 2>/dev/null) && echo "$git_root"

Note: git rev-parse --show-toplevel will fail if the current directory is NOT inside a git repo (e.g. a plain parent folder containing multiple repos). That is expected — rely on find as the primary discovery method, and use git rev-parse only as a fallback to catch the case where cwd is deep inside a single repo.

Deduplicate the combined results to build the final repo list. Present to the user:

  • If only one repo found: use it directly, move to step 3.
  • If multiple repos found: list them with their current branch and short status, then let the user select which ones to include:
Found 3 git repos in this workspace:

  1. service-a       (on main, clean)
  2. service-b       (on main, 2 uncommitted changes)
  3. lib-common      (on develop, clean)

Which repos should I create worktrees for? (e.g. "1,3" or "all")

2. Configure Worktree

Ask the Purpose

Ask the user what they are working on:

What bug or feature is this worktree for?
(e.g. "fix the login timeout issue" or "add dark mode support")

Suggest Branch Names

Based on their answer, suggest 2-3 meaningful branch/worktree names:

  • User says "fix the login timeout issue" -> suggest:

1. bugfix/login-timeout

  • User says "add dark mode support" -> suggest:

1. feature/dark-mode 2. feature/dark-mode-support

Use the convention: bugfix/ for bugs, feature/ for features. Do not use shortcuts like fix/ or feat/. Let the user pick one or type their own.

Ask Worktree Location

Where should I create the worktree(s)?

  1. .worktrees/<branch-name>/ inside each repo (project-local, hidden)
  2. Shared folder at the workspace level (e.g. ../.worktrees/<branch-name>/)
  3. ~/.worktrees/<project>/<branch-name>/ (global location)
  4. Custom path

Which do you prefer?

In all cases, the worktree directory is named after the branch/feature name. For example, if the branch is bugfix/login-timeout, worktrees are placed under a login-timeout/ folder within the chosen location. This keeps worktrees organized by the feature or bug they relate to.

For multi-repo workspaces, the worktree folder mirrors the original workspace layout so that opening it as a new workspace auto-detects all the git repos inside it:

.worktrees/login-timeout/
├── service-a/        <-- git worktree (auto-detected as git repo)
├── service-b/        <-- git worktree (auto-detected as git repo)
└── lib-common/       <-- git worktree (auto-detected as git repo)

The user can open .worktrees/login-timeout/ directly in their IDE and it will automatically recognize each subdirectory as a git repo, just like the original workspace.

Verify.gitignore (project-local only)

If the user chose a project-local location, verify it is git-ignored:

git check-ignore -q .worktrees 2>/dev/null

If NOT ignored, add the entry to .gitignore and commit:

echo ".worktrees/" >> .gitignore
git add .gitignore
git commit -m "Add .worktrees/ to .gitignore"

Per-Repo Branch Overrides (multi-repo only)

If multiple repos are selected, the chosen branch name applies to all by default. Ask:

Use branch "feature/dark-mode" for all 3 repos, or override per repo?

If the user wants overrides, let them specify a branch name for each repo.

Existing Worktree Detection

Before creating, check if a worktree already exists for the target branch:

git worktree list | grep <branch-name>

If found, offer to reuse or recreate it.


3. Create Worktrees + Copy.env Files

For each selected repo:

Create the Worktree

git worktree add <worktree-path> -b <branch-name>

Copy Untracked.env Files

Find all untracked .env files in the original repo checkout (the source, not the worktree):

# Find untracked/ignored .env files
find <original-repo> -maxdepth 3 -name '.env*' -not -path '*/.git/*' 2>/dev/null

Filter to only files that are NOT tracked by git:

git -C <original-repo> ls-files --error-unmatch <file> 2>/dev/null
# If this fails (exit code 1), the file is untracked -> copy it

Common patterns to look for: .env, .env.local, .env.development, .env.test, .env.production, and any nested .env files in subdirectories.

Copy each found untracked .env file to the same relative path in the new worktree:

cp <original-repo>/.env <worktree-path>/.env
cp <original-repo>/config/.env.local <worktree-path>/config/.env.local

Report which files were copied. Never commit or stage these files.


4. Project Setup

Auto-detect the project type in each worktree and install dependencies.

Do NOT run tests unless the user explicitly asks.

Multiple Python Repos: Shared Virtual Environment

When 2 or more selected repos are Python projects (detected by setup.py, setup.cfg, or pyproject.toml with a [project] or [tool.setuptools] section), create a single shared virtualenv instead of per-repo venvs:

python -m venv <workspace-or-worktree-parent>/.venv
source <workspace-or-worktree-parent>/.venv/bin/activate
pip install -e <repo-a-worktree> -e <repo-b-worktree> -e <repo-c-worktree>

This ensures cross-repo imports resolve to the editable worktree code. Use a single pip install -e call with all repos and let pip resolve the dependency order.

Place the venv at the workspace level (e.g. workspace/.venv/) or next to the chosen worktree location parent.

Report the venv path and activation command in the summary.

Single Python Repo

python -m venv <worktree-path>/.venv
source <worktree-path>/.venv/bin/activate
pip install -e <worktree-path>

Or if the repo uses requirements.txt without a setup.py/pyproject.toml:

pip install -r <worktree-path>/requirements.txt

Other Project Types

# Node.js
if [ -f package.json ]; then npm install; fi

# Rust
if [ -f Cargo.toml ]; then cargo build; fi

# Go
if [ -f go.mod ]; then go mod download; fi

For non-Python repos in a mixed workspace, fall back to these per-repo setups.


5. Report Summary

Print a summary table for all created worktrees:

| Repo       | Branch             | Worktree Path              | .env Copied        | Status |
|------------|--------------------|----------------------------|--------------------:|--------|
| service-a  | feature/dark-mode  | service-a/.worktrees/dm    | .env, .env.local   | Ready  |
| lib-common | feature/dark-mode  | lib-common/.worktrees/dm   | .env               | Ready  |

If a shared Python venv was created, also report:

Shared virtualenv: workspace/.venv/
Activate with:     source workspace/.venv/bin/activate

For a single repo, a simple report is fine:

Worktree ready at <full-path>
Branch: <branch-name>
Copied .env files: .env, .env.local
Ready to implement <feature-description>

6. Cleanup / Teardown

When the user asks to clean up worktrees:

List Active Worktrees

Scan all repos in the workspace and list active worktrees:

# For each repo
git -C <repo> worktree list

Present a numbered list and let the user select which to remove.

Safety Checks

Before removing, check for uncommitted changes:

git -C <worktree-path> status --porcelain

If there are uncommitted changes, warn the user and prompt for confirmation before force-removing.

Remove Worktrees

Always ask the user for explicit permission before removing each worktree:

Remove worktree at <worktree-path>? (y/n)

Only proceed after the user confirms:

git -C <repo> worktree remove <worktree-path>

If the worktree has uncommitted changes, require a second explicit confirmation:

WARNING: <worktree-path> has uncommitted changes. Force-remove anyway? (y/n)

Only if the user confirms again:

git -C <repo> worktree remove --force <worktree-path>

Clean Up Branches

Always ask the user for explicit permission before deleting each branch:

Delete branch <branch-name>? (merged: yes/no) (y/n)

If merged and user confirms:

git -C <repo> branch -d <branch-name>

If not merged, warn clearly and only delete with -D if the user explicitly confirms:

WARNING: Branch <branch-name> is NOT merged. Delete anyway? This cannot be undone. (y/n)

Clean Up Shared Venv

Always ask the user for explicit permission before deleting the shared venv:

All worktrees using workspace/.venv/ have been removed. Delete the shared venv? (y/n)

Only delete after the user confirms.

General Rule

Never perform any delete operation (worktree removal, branch deletion, venv deletion) without explicit user permission. Always ask first, always wait for confirmation.


Quick Reference

SituationAction
Single repo detectedUse directly, skip selection
Multiple repos detectedList with status, let user select
User describes bugSuggest bugfix/ branch names
User describes featureSuggest feature/ branch names
Project-local worktree dir not ignoredAdd to .gitignore and commit
Worktree already exists for branchOffer to reuse or recreate
Untracked .env files foundCopy to worktree, never commit them
Multiple Python repos selectedCreate shared venv with pip install -e
Single Python repoCreate per-repo venv
Non-Python repoAuto-detect and run setup (npm, cargo, go)
TestsDo NOT run unless user explicitly asks
Any delete operationAlways ask user for explicit permission first
Cleanup with uncommitted changesWarn and require double confirmation
Branch not merged on cleanupWarn clearly, only -D with explicit confirmation
All worktrees removed for shared venvAsk before deleting the venv

Common Mistakes

Skipping.gitignore verification

  • Problem: Worktree contents get tracked, pollute git status
  • Fix: Always use git check-ignore before creating project-local worktrees

Forgetting to copy.env files

  • Problem: Worktree fails to run because of missing environment config
  • Fix: Always scan for untracked .env* files and copy them over

Creating separate venvs for interdependent Python repos

  • Problem: Cross-repo imports fail because each venv only has its own repo installed
  • Fix: Detect multiple Python repos and create a shared venv with pip install -e

Running tests without being asked

  • Problem: Wastes time, may fail due to missing external services
  • Fix: Only run tests when the user explicitly requests it

Deleting anything without asking

  • Problem: Loses uncommitted work, removes branches or venvs the user still needs
  • Fix: Always ask for explicit user permission before every delete operation (worktree, branch, venv)

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.57%
按下载量换算24

Claude

29.84%
按下载量换算19

Cursor

18.35%
按下载量换算12

Gemini CLI

9.72%
按下载量换算6

安全审计

Gen Agent Trust Hub

可疑

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills