Nettoyage automatique des worktrees

VérifiéPrudence

Nettoie automatiquement les worktrees Git et retourne à la branche de base. Préserve les branches locales et distantes.

Spar Skills Guide Bot
DeveloppementIntermédiaire
2024/07/2026
Claude CodeCursorWindsurf
#git#worktree#cleanup#branching

Recommandé pour

Notre avis

Automatise le nettoyage d'un worktree git en détectant la branche courante, en vérifiant les modifications non commit, en supprimant le worktree et en revenant à la branche de base.

Points forts

  • Gagne du temps en automatisant les étapes multiples de nettoyage
  • Prévient la suppression accidentelle des branches locales et distantes
  • Gère les erreurs courantes comme les modifications non commit avec des messages clairs
  • Permet de spécifier une branche de base et de forcer l'exécution si nécessaire

Limites

  • Ne fonctionne que depuis un répertoire de worktree
  • Ne supprime pas les branches locales ou distantes
  • Nécessite que toutes les modifications soient commit par défaut
Quand l'utiliser

À utiliser après avoir terminé le travail dans un worktree et avant de changer de branche pour maintenir un environnement de développement propre.

Quand l'éviter

Ne pas utiliser si vous souhaitez conserver le répertoire de worktree pour un travail futur, ou si vous avez des modifications non commit et ne pouvez pas forcer.

Analyse de sécurité

Prudence
Score qualité90/100

The skill uses Bash with extensive permissions to run a cleanup script that performs git operations (remove worktree, checkout base branch). While the intended actions are safe and non-destructive, the broad Bash access poses a moderate risk if the script were to be modified or misused. No destructive or exfiltrating instructions are directly included.

Points d'attention
  • Broad Bash access (Bash(bash:*)) could permit execution of arbitrary commands if the cleanup script is compromised.

Exemples

Clean up current worktree
I'm done with this worktree, please clean it up and switch back to main.
Clean up to develop branch
Clean up the current worktree and checkout the develop branch.
Force cleanup with uncommitted changes
Force clean up this worktree even if there are uncommitted changes, but I want to keep the branch.

name: worktree-cleanup description: Automatically cleanup the worktree and return to the base branch. Keeps local and remote branches intact. Check after creating PR or pushing. allowed-tools: Bash(git:), Bash(cd:), Bash(pwd:), Bash(bash:)

Worktree Cleanup

Automatically cleans up the worktree after development is complete.

Overview

This skill performs the following steps automatically:

  1. Detects the current worktree directory and branch
  2. Checks for uncommitted changes
  3. Removes the worktree
  4. Checks out the base branch (default: main)

Important: Local and remote branches are preserved (not deleted).

Usage

Basic Usage

# Run from within the worktree directory
bash scripts/worktree_cleanup.sh

Options

# Specify a base branch
bash scripts/worktree_cleanup.sh --base develop

# Skip confirmation prompt
bash scripts/worktree_cleanup.sh --yes

# Ignore uncommitted changes (not recommended)
bash scripts/worktree_cleanup.sh --force

Prerequisites

  • Must be run from within a worktree directory
  • All changes must be committed (or use the --force option)

Error Handling

Uncommitted Changes Detected

The script will stop and prompt you to commit. You can force execution with --force, but this is not recommended.

Worktree Removal Failed

Manual removal instructions will be displayed.

Running Outside a Worktree

A warning is displayed and the process is aborted.

Details

See REFERENCE.md for internal processing flow, troubleshooting, and best practices.

Skills similaires