用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/FlorianBruniaux/claude-code-ultimate-guide --skill git-worktree-remove命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
基于 SOC 职业分类
正在显示 SKILL.md
| name | git-worktree-remove |
| description | Safely remove a git worktree with branch cleanup and safety checks |
| argument-hint | <worktree_name> |
| effort | low |
| when_to_use | Use when removing a specific worktree by name. |
| disable-model-invocation | true |
Safely remove a single git worktree with branch cleanup, merge verification, and database branch teardown.
Core principle: Safety checks first, then clean removal of worktree + branch + DB resources.
Part of: Worktree Lifecycle Suite | /git-worktree | /git-worktree-status | /git-worktree-clean
git worktree removegit branch -d (or -D with confirmation)git push origin --delete (with confirmation)git worktree prune# Never remove worktrees for these branches (configurable)
PROTECTED_BRANCHES="main master develop staging production"
if echo "$PROTECTED_BRANCHES" | grep -qw "$BRANCH"; then
echo "BLOCKED: Cannot remove worktree for protected branch '$BRANCH'"
echo "Protected branches: $PROTECTED_BRANCHES"
exit 1
fi
cd "$WORKTREE_PATH"
if [ -n "$(git status --porcelain)" ]; then
echo "WARNING: Worktree has uncommitted changes:"
git status --short
echo ""
echo "Options:"
echo " 1. Commit changes first"
echo " 2. Force remove (--force)"
echo " 3. Cancel"
# Wait for user decision
fi
# Check if branch is merged into main
MAIN_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
if git merge-base --is-ancestor "$BRANCH" "$MAIN_BRANCH" 2>/dev/null; then
echo "Branch '$BRANCH' is merged into $MAIN_BRANCH. Safe to delete."
MERGED=true
else
echo "WARNING: Branch '$BRANCH' is NOT merged into $MAIN_BRANCH."
echo "You may lose work if you delete this branch."
MERGED=false
fi
# 1. Remove the worktree
git worktree remove "$WORKTREE_PATH"
# If dirty state and user confirmed force:
# git worktree remove --force "$WORKTREE_PATH"
# 2. Delete local branch
if [ "$MERGED" = true ]; then
git branch -d "$BRANCH"
else
echo "Delete unmerged branch '$BRANCH'? (requires confirmation)"
# On confirmation:
git branch -D "$BRANCH"
fi
# 3. Delete remote branch (with confirmation)
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
echo "Delete remote branch 'origin/$BRANCH'?"
# On confirmation:
git push origin --delete "$BRANCH"
fi
# 4. Prune stale references
git worktree prune
After worktree removal, remind about associated database branches:
# Detect database provider (same logic as /git-worktree)
if [ -f ".env" ] && grep -q "neon" ".env"; then
echo ""
echo "DB Cleanup: neonctl branches delete $BRANCH_SLUG"
elif [ -f ".pscale.yml" ]; then
echo ""
DB_NAME=$(grep 'database:' .pscale.yml | awk '{print $2}')
echo "DB Cleanup: pscale branch delete $DB_NAME $BRANCH_SLUG"
elif [ -f ".env" ] && grep -q "postgresql" ".env"; then
echo ""
echo "DB Cleanup: psql \$DATABASE_URL -c \"DROP SCHEMA ${BRANCH_SLUG} CASCADE;\""
fi
Successful removal (merged branch):
Removed worktree: .worktrees/feat/auth
Worktree directory: deleted
Local branch feat/auth: deleted (was merged)
Remote branch origin/feat/auth: deleted
References: pruned
DB reminder: neonctl branches delete feat-auth
Removal with warnings (unmerged branch):
Removed worktree: .worktrees/feat/experimental
Worktree directory: deleted
Local branch feat/experimental: deleted (was NOT merged - forced)
Remote branch: no remote branch found
References: pruned
WARNING: Branch was not merged. Changes may be lost.
Last commit: a1b2c3d "WIP: experimental auth flow"
| Flag | Effect |
|---|---|
--force | Skip uncommitted changes warning |
--keep-branch | Remove worktree but keep the branch |
--keep-remote | Don't delete remote branch |
| Situation | Action |
|---|---|
| Branch is merged | Safe delete (branch -d) |
| Branch is unmerged | Warn + require confirmation (branch -D) |
| Uncommitted changes | Warn + offer force/cancel |
| Protected branch (main/develop) | Block removal |
| Remote branch exists | Ask to delete remote |
| DB branch detected | Remind with exact command |
| Stale references | Auto-prune |
Removing worktree for main/develop
Deleting unmerged branch without checking
--force or -D.Forgetting database branch cleanup
Using rm -rf instead of git worktree remove
.git/worktrees/. Always use git commands./git-worktree-remove feat/auth
/git-worktree-remove fix/login-bug --force
/git-worktree-remove refactor/db --keep-branch
Branch or worktree path: $ARGUMENTS