repository-hygiene-sweep
Installation
SKILL.md
repository-hygiene-sweep — clean a repository without destroying useful work
Maintain a git repository: prune merged branches, compact storage, hunt large/dangling objects, and (only with explicit consent) rewrite history to remove accidental large files or secrets. The discipline is conservation — every step is reversible-first, and anything ambiguous is skipped, not guessed.
⚠️ Critical Constraints
- Never run a destructive command without explicit, scoped confirmation. Branch deletion, history rewrite,
reflog expire, andgc --prune=noware the destructive set. Name exactly what will be destroyed and wait for a yes. Why: these are the operations that lose real work, and the user often does not realize what a branch or reflog entry was protecting. - Skip when in doubt — never guess. If you cannot prove a branch is fully merged, a file is truly junk, or a repo is not shared, do nothing and report the ambiguity. Why: the cost of a wrong delete (lost work) vastly exceeds the cost of leaving a stale branch around.
- Read-only first; mutate only after. Run the diagnosis pass (counts, sizes, candidate lists) and present it before changing anything. Why: the user must see what they are approving.
- WRONG:
git branch --merged | grep -v '\*' | xargs git branch -d(auto-deletes on a single guess) - CORRECT: list
git branch --merged main, show it, get confirmation, then delete named branches one set at a time.
- WRONG:
- Never delete a branch that is not merged with
-D. Use-d(refuses to delete unmerged). Why:-Dforce-deletes branches that contain unique commits — the classic way to silently lose work.- WRONG:
git branch -D feature/x - CORRECT:
git branch -d feature/xand, if it refuses, investigate why instead of forcing.
- WRONG:
- Never rewrite published/shared history casually. History rewrite (filter-repo, BFG) is acceptable only on a repo the owner confirms is unshared or whose collaborators have agreed to re-clone. Why: rewriting shared history breaks every other clone and can resurrect "deleted" data on the next push.
- Always confirm a clean, backed-up state before any history rewrite. Require a committed/clean working tree and a fresh mirror clone (
git clone --mirror) as the backup. Why: history rewrite is the one operation with no in-repo undo once reflogs are expired. - A leaked secret is not "removed" by rewriting history alone. Always advise rotating/revoking the secret too. Why: the secret may already be cloned, cached, or on a fork — rotation is the only real remediation.