Back to catalog

worktree-cleanup

Clean up merged or stale git worktrees to free disk space and maintain organization. Use after merging PRs or when worktrees are no longer needed.

  • Category: discovered
  • Tags: github, community
  • Version: 1.0.0
  • Author: walid
  • Downloads: 0
  • GitHub stars: 4
  • Updated: 2025-11-21

Download the latest version (v1.0.0) from this page.

SKILL.md

---
name: worktree-cleanup
description: Clean up merged or stale git worktrees to free disk space and maintain organization. Use after merging PRs or when worktrees are no longer needed.
---

# Worktree Cleanup Skill

Clean up git worktrees after work is complete.

## When to Use

- After PR is merged
- Worktree no longer needed
- Free disk space
- Maintain clean worktree list

## Usage

### Remove Single Worktree

```bash
# Remove specific worktree
./scripts/remove_worktree.sh 42

# Or by path
git worktree remove ../ml-odyssey-42-feature
```text

### Clean Up Merged Worktrees

```bash
# Remove all merged worktrees
./scripts/cleanup_merged_worktrees.sh

# This
# 1. Checks which branches are merged
# 2. Finds worktrees for merged branches
# 3. Removes them (with confirmation)
```text

### Force Remove

```bash
# Force remove (if has uncommitted changes)
git worktree remove --force ../ml-odyssey-42-feature
```text

## Safety Checks

Before removing, verify:

- Branch is merged or no longer needed
- No uncommitted changes (or backed up)
- Not currently in worktree

```bash
# Check status before removing
cd ../ml-odyssey-42-feature
git status
cd ../ml-odyssey

# Then remove
git worktree remove ../ml-odyssey-42-feature
```text

## Scripts

- `scripts/cleanup_merged_worktrees.sh` - Auto-clean merged
- `scripts/list_stale_worktrees.sh` - Find old worktrees
- `scripts/remove_worktree.sh` - Remove single worktree

See `worktree-create` skill for creating worktrees.