Skip to content
Back to skills

Git Workspace Cleanup

ASecurity

Destructive Git cleanup workflow that keeps only the main worktree and local main branch, then updates main; not for routine status checks, partial cleanup, or implicit repository hygiene.

  • 30 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added November 8, 2026
ai-agentspythonshellbashgit

Security analysis

A100/100

Scanned November 8, 2026

npx -y skills add majiayu000/claude-skill-registry-data --skill git-workspace-cleanup --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Workspace Cleanup?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Workspace Cleanup
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/majiayu000-git-workspace-cleanup/badge)](https://www.skillsdirectory.com/skills/majiayu000-git-workspace-cleanup)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-workspace-cleanup
description: Destructive Git cleanup workflow that keeps only the main worktree and local main branch, then updates main; not for routine status checks, partial cleanup, or implicit repository hygiene.
---

# Git Workspace Cleanup

Return a Git repository to a single clean main worktree: remove every non-main worktree, delete every local branch except `main`, and fast-forward `main` from its remote.

This is destructive. Never run it implicitly.

## Invocation

Use this skill only when the user explicitly invokes it as `$git-workspace-cleanup`.

## Required Flow

1. State that the workflow can delete local worktrees and branches.
2. Resolve the bundled script relative to this `SKILL.md`:

   ```text
   scripts/git_workspace_cleanup.py
   ```

3. Choose the Python 3 launcher available in the user's shell and call it `<python>` in the commands below:

   - POSIX shells commonly use `python3`.
   - Windows PowerShell or `cmd.exe` commonly use `py -3` or `python`.

4. Run the bundled script in dry-run mode from any path inside the repository. The dry run fetches the remote and verifies the preserved branch can fast-forward before reporting the destructive plan:

   ```bash
   <python> <skill-dir>/scripts/git_workspace_cleanup.py --repo . --dry-run
   ```

5. Show the user the main worktree path and the worktrees and branches that would be removed.
6. Ask for explicit approval before mutating the repository. Use the host's native user-input or approval UI when it is available; in Codex, use `request_user_input` when the current mode exposes it. Offer a destructive approval choice and a cancel choice. If no native choice UI is available, ask for a short typed approval phrase instead.
7. After approval, run:

   ```bash
   <python> <skill-dir>/scripts/git_workspace_cleanup.py --repo . --yes
   ```

8. Continue subsequent repository work from the printed main worktree path.
9. Verify the final state with:

   ```bash
   git worktree list
   git branch --format="%(refname:short)"
   git status --short --branch
   git pull --ff-only
   ```

Use `--repo <path>` when the current shell is not inside the target repository.

## Safety Rules

- Do not remove the worktree checked out on `main`.
- Do not delete the local `main` branch.
- Do not mutate anything unless the user approves the dry-run result.
- Stop if the main worktree is dirty.
- Stop if an extra worktree is dirty. Use `--force-worktrees` only when the user explicitly approves discarding files in those dirty extra worktrees. Prefer the host's native user-input or approval UI for this approval when available; otherwise require a typed approval phrase.
- Treat fast-forward failure as a blocker before removing worktrees or deleting branches. Do not merge, rebase, reset, or force-push as part of this skill.
- If the repository uses a preserved branch other than `main`, rerun the script with `--main-branch <branch>` only after the user confirms that branch name.

## Script Behavior

The bundled script:

- locates the worktree checked out on the preserved branch, defaulting to `main`
- runs `git fetch --prune <remote>`, defaulting to `origin`
- verifies the preserved branch can fast-forward to `<remote>/<main-branch>`
- removes every other worktree
- deletes every other local branch with `git branch -D`
- runs `git pull --ff-only <remote> <main-branch>`, defaulting to `origin main`

The script requires Python 3.9 or newer and either `--dry-run` or `--yes`; it refuses to mutate by default.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.