/gsd cleanup
What It Does
Section titled “What It Does”/gsd cleanup is a housekeeping command that removes accumulated git debris from a GSD project. It covers two categories of stale artifacts: merged GSD branches and old execution snapshot refs.
Running /gsd cleanup with no arguments handles both cases at once. Each category can also be targeted individually with a subcommand.
The command reports what it removed (or why it skipped), then exits. There is no dry-run confirmation step — cleanup is low-risk because it only removes branches that are already merged into main and snapshot refs that have been superseded by newer ones.
/gsd cleanup/gsd cleanup branches/gsd cleanup snapshots| Form | What it does |
|---|---|
/gsd cleanup | Runs both branches and snapshots cleanup together |
/gsd cleanup branches | Delete merged gsd/* branches |
/gsd cleanup snapshots | Prune old refs/gsd/snapshots/ refs, keeping the 5 most recent per label |
How It Works
Section titled “How It Works”Branch Cleanup
Section titled “Branch Cleanup”Branch cleanup runs in a straightforward sequence:
- List GSD branches — Finds all local branches matching
gsd/*. - Check for merges — Uses
git branch --mergedagainst the detected main branch to find whichgsd/*branches are fully contained in main. - Delete merged branches — Removes each merged branch with a standard (non-force) delete. Branches that can’t be deleted are silently skipped.
- Report — Shows how many were removed and how many remain.
If no gsd/* branches exist at all, or none are merged yet, the command says so and exits cleanly.
Snapshot Cleanup
Section titled “Snapshot Cleanup”GSD uses refs/gsd/snapshots/ to store undo snapshots during task execution. These accumulate over time. Snapshot cleanup:
- Lists all refs under
refs/gsd/snapshots/ - Groups them by label (the path prefix, excluding the final timestamp segment)
- For each label group, keeps the 5 most recent refs (sorted lexicographically, which matches chronological order given the
YYYYMMDD-HHMMSStimestamp format) and deletes the rest
This means you always have at least 5 rollback points per label. Old snapshots beyond that window are pruned.
What Files It Touches
Section titled “What Files It Touches”| File | Purpose |
|---|---|
git branch list (gsd/*) | Identifies GSD-managed branches to check for merges |
git refs (refs/gsd/snapshots/) | Finds snapshot refs to prune |
Deletes
Section titled “Deletes”| Artifact | Condition |
|---|---|
git branches (gsd/*) | Merged into main |
git refs (refs/gsd/snapshots/<label>/<old>) | Beyond the 5-per-label window for that snapshot label |
Examples
Section titled “Examples”Default cleanup — branches and snapshots together:
> /gsd cleanup
Cleaned up 3 merged branches. 1 remain.Pruned 12 old snapshot refs. 10 remain.No branches exist:
> /gsd cleanup branches
No GSD branches to clean up.Branches exist but none merged yet:
> /gsd cleanup branches
4 GSD branches found, none are merged into main yet.Branches cleaned up:
> /gsd cleanup branches
Cleaned up 2 merged branches. 1 remain.No old snapshots to prune:
> /gsd cleanup snapshots
No snapshot refs to clean up.Related Commands
Section titled “Related Commands”/gsd health— Diagnose.gsd/directory health and repair structural issues/gsd complete-milestone— Archive a shipped milestone/gsd undo— Roll back to a recent snapshot