Git Worktree Remove logo

Git Worktree Remove

CommunityPopular
FlorianBruniaux
git-worktree-remove

Safely remove a git worktree with branch cleanup and safety checks

Overview

PublisherFlorianBruniaux
Repositoryclaude-code-ultimate-guide
Skill namegit-worktree-remove
Stars
6K
Forks
782
Bundled files
Instructions only
LicenseCC-BY-SA-4.0
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by FlorianBruniaux on GitHub. Read the source before you install it.

Installation

Install the Git Worktree Remove AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/FlorianBruniaux/claude-code-ultimate-guide.git /tmp/claude-code-ultimate-guide
mkdir -p .claude/skills
cp -r /tmp/claude-code-ultimate-guide/examples/skills/git-worktree-remove .claude/skills/git-worktree-remove
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Git Worktree Remove in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Git Worktree Remove on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Git Worktree Remove is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Git Worktree Remove

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

Process

  1. Validate Target: Identify worktree to remove
  2. Safety Check: Protect main/develop branches
  3. Check Merge Status: Warn if branch has unmerged changes
  4. Check Uncommitted Changes: Warn if worktree has dirty state
  5. Remove Worktree: git worktree remove
  6. Delete Local Branch: git branch -d (or -D with confirmation)
  7. Delete Remote Branch: git push origin --delete (with confirmation)
  8. Database Cleanup Reminder: Suggest DB branch deletion if applicable
  9. Prune References: git worktree prune

Safety Checks

Protected Branches

bash
# 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

Uncommitted Changes

bash
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

Merge Status

bash
# 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

Removal Steps

bash
# 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

Database Branch Cleanup

After worktree removal, remind about associated database branches:

bash
# 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

Report Format

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"

Flags

FlagEffect
--forceSkip uncommitted changes warning
--keep-branchRemove worktree but keep the branch
--keep-remoteDon't delete remote branch

Quick Reference

SituationAction
Branch is mergedSafe delete (branch -d)
Branch is unmergedWarn + require confirmation (branch -D)
Uncommitted changesWarn + offer force/cancel
Protected branch (main/develop)Block removal
Remote branch existsAsk to delete remote
DB branch detectedRemind with exact command
Stale referencesAuto-prune

Common Mistakes

Removing worktree for main/develop

  • Always blocked by safety check. Reconfigure protected branches if needed.

Deleting unmerged branch without checking

  • Always verify merge status. Unmerged branches require explicit --force or -D.

Forgetting database branch cleanup

  • Leaves orphaned DB branches consuming resources. Command reminds automatically.

Using rm -rf instead of git worktree remove

  • Leaves stale worktree references in .git/worktrees/. Always use git commands.

Usage

/git-worktree-remove feat/auth
/git-worktree-remove fix/login-bug --force
/git-worktree-remove refactor/db --keep-branch

Branch or worktree path: $ARGUMENTS

Frequently asked questions

What does the Git Worktree Remove AI skill do?

Safely remove a git worktree with branch cleanup and safety checks

Why use Git Worktree Remove on TypingMind?

Because you install it once and use it with any model. Git Worktree Remove is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Git Worktree Remove in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/FlorianBruniaux/claude-code-ultimate-guide/tree/main/examples/skills/git-worktree-remove. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Git Worktree Remove?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Git Worktree Remove?

As many as you like. As long as a model supports skills, you can use Git Worktree Remove with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Git Worktree Remove AI skill free?

Yes. It is published on GitHub by FlorianBruniaux under the CC-BY-SA-4.0 license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇