Skip to content
Back to skills

Git Cleanup

ASecurity

Use when a git worktree is dirty or another local branch or worktree exists. Ask before cleanup unless the session is unattended.

  • 5 stars
  • 0 votes
  • 0 copies
  • 4 views
  • Added November 24, 2026
ai-agentsbashgit

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add ShaftHQ/chaosengine-harness --skill git-cleanup --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Cleanup?

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

Security grade badge for Git Cleanup
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/shafthq-git-cleanup/badge)](https://www.skillsdirectory.com/skills/shafthq-git-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-cleanup
description: Use when a git worktree is dirty or another local branch or worktree exists. Ask before cleanup unless the session is unattended.
permissions:
  - bash
  - read
  - write
---

# Git cleanup

One checkout on the configured default branch. `HEAD` equals that remote tip. `git status` is clean.

## When

The worktree is dirty, or another local branch or linked worktree exists.

Attended: ask first, and explain this procedure before changing anything.
Unattended: decide and run it.

## Procedure

Name the configured default branch from the remote HEAD or the selected profile. Do not hardcode a repository branch name. This is the repository-scope recipe in cleanup-scopes. Do not fork a second policy.

1. Fetch and prune the configured upstream. Inventory dirty and untracked paths, extra local branches, linked worktrees, locks, and unique commits before mutation.
2. Classify each dirty or untracked path as land (commit, push, pull request, merge), delete, or gitignore. Halt on a locked or concurrently owned worktree.
3. Check out the configured default branch in the primary checkout and fast-forward it so `HEAD` equals the remote tip and `git status` is clean.
4. Remove extra linked worktrees only after that classification, and only when they are clean, unlocked, and not concurrently owned. Then remove a recreated local branch only when `git branch -r --contains` shows that exact tip on an origin ref. Also remove extra local branches that are fully merged into the remote tip, or whose unique commits were explicitly authorized for discard.
5. Check out the configured default branch and fast-forward it. Write the verification transcript in the same process, after that fast-forward. Do not check out another branch afterward.

## Done

One checkout, only the configured default branch, `HEAD` equals that remote tip, and `git status` is clean.

## Limits

Do not stash. Do not `reset --hard`. Do not force-push. Do not use `--force-with-lease`. Do not delete remote branches. Do not rewrite remote history. Do not discard unique commits without explicit authorization. Do not commit generated plugin directories.

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.