git-hygiene
Skill0 starsChanged 6 months agoMITView on GitHub
Analyze cluttered git repositories, propose a safe cleanup plan, group mixed changes into coherent commits, and prune stale branches. Use when the user asks to clean up git, tidy a repo, organize mixed uncommitted work, sort untracked files, or prune stale branches. Do not use for merge conflict resolution, active rebase, merge, cherry-pick, or bisect states, submodule modification, or pushing and PR creation.
- Reads credentials
- Deletes or force-pushes
- Installs packages
We split this skill into the rules it gives an agent
70 rules. 0 are common, 52 are distinctive, and 18 are very specific to this project.
0
Common
Most of the 3 edited versions we read keep these.
52
Distinctive
This author's own choices. Worth a look.
18
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Verify that the current directory is inside a git repository before doing anything else.
- Very specific: line 14
Default to audit mode unless the user clearly asked for a specific execution lane.
- Distinctive: line 20
Never skip preview, even if the user says "just do it."
- Very specific: line 21
Use a reversible deletion mechanism (move-to-trash semantics) for approved file deletions.
- Distinctive: line 25
Create the cleanup branch only for modes that modify the working tree or create commits.
- Distinctive: line 26
Do not push, open PRs, rewrite history, or modify submodules.
- Distinctive: line 30
Use one of these modes for each run:
- Very specific: line 41
If the user asks for "clean up git" without naming a mode, run audit.
- Distinctive: line 46
Treat submodules as read-only.
- Distinctive: line 47
Treat unknown files conservatively.
- Distinctive: line 48
Treat protected-pattern files conservatively.
- Distinctive: line 49
If analysis finds nothing worth cleaning, report that the repository is already clean and stop.
- Very specific: line 50
Follow repo-specific branch conventions when they are explicit.
- Distinctive: line 56
Not inside a git repository: stop and tell the user what directory you checked.
- Distinctive: line 65
Always do preflight first, regardless of mode.
- Distinctive: line 73
if rebase, merge, cherry-pick, or bisect is in progress, abort cleanly
- Distinctive: line 78
if the repo exceeds the large-repo threshold, pause for confirmation
- Very specific: line 80
if .git-hygiene.json exists at repo root, load and apply it
- Distinctive: line 81
if the file is malformed, report that and ignore it for this run
- Distinctive: line 85
Run audit on the current branch.
- Very specific: line 100
Never auto-delete ask or protected files.
- Distinctive: line 101
Never auto-ignore source-looking files.
- Very specific: line 102
Treat .gitignore updates as infrastructure changes that belong in their own commit.
- Distinctive: line 117
If the user only wants commit hygiene, this lane can run independently.
- Distinctive: line 126
Before proposing branch deletion:
- Distinctive: line 128
check whether the branch is checked out in another worktree
- Distinctive: line 130
keep local branch deletion and remote-tracking prune separate in both preview and approval because the former is destructive and the latter …
- Distinctive: line 141
Treat this lane as optional.
- Distinctive: line 177
If the user says "skip preview" or "just do it," shorten the preview but still show the lane summary and ask for confirmation.
- Distinctive: line 201
If the user changes any lane materially, regenerate the preview for that lane and reconfirm before execution.
- Distinctive: line 217
Do not mutate anything.
- Distinctive: line 225
Create the cleanup branch only if approved safe work will modify the working tree or create commits.
- Very specific: line 226
Create one for .gitignore changes, commit-shaping, or repo-root config changes that the user wants isolated.
- Distinctive: line 227
Do not create one for remote prune alone.
- Very specific: line 231
Write approved .git-hygiene.json updates if the user wanted them.
- Distinctive: line 233
Do not delete files or local branches in this mode.
- Distinctive: line 242
Create the cleanup branch only if approved file deletions should be isolated in the working tree.
- Distinctive: line 243
Do not create one for local branch deletion alone.
- Very specific: line 244
Delete approved files using a reversible mechanism (e.g., trash on macOS, trash-put on Linux, gio trash on GNOME).
- Distinctive: line 245
Default: do not stage or commit those deletions in this mode.
- Very specific: line 246
Leave the deleted files as explicit working-tree changes unless the user later runs commit-only or apply-safe with an approved commit group …
- Distinctive: line 247
Delete approved local branches that are safe to delete and not active in any worktree.
- Distinctive: line 249
Do not smuggle in unrelated safe actions here.
- Distinctive: line 250
Do not create commits or stage deletions in this mode.
- Distinctive: line 256
Create the cleanup branch if commit creation should be isolated.
- Distinctive: line 258
Create each approved commit with the approved Conventional Commits message.
- Distinctive: line 260
Do not modify untracked-file decisions or branch state outside what the commit lane explicitly needs.
- Very specific: line 266
Do not create a cleanup branch, create commits, or edit .gitignore in this mode.
- Distinctive: line 272
Delete approved local branches that passed the worktree and protection checks.
- Distinctive: line 278
Stop immediately on any failure.
- Distinctive: line 287
Do not guess, continue, or rollback automatically.
- Distinctive: line 292
Never delete files without explicit approval.
- Distinctive: line 293
Never delete protected files from batch approval alone.
- Very specific: line 294
Never use rm or git clean -fd.
- Distinctive: line 295
Never collapse unrelated changes into one "cleanup" commit without first proposing better grouping.
- Distinctive: line 296
Never delete branches without checking worktree usage.
- Distinctive: line 297
Never create cleanup branches for audit-only or no-op runs.
- Distinctive: line 298
Never mix destructive and non-destructive execution behind one vague approval.
- Distinctive: line 299
Never treat remote prune approval as approval to delete local branches.
- Very specific: line 305
If the user did not explicitly choose a mode, use audit.
- Very specific: line 309
Ask per file: track, ignore, delete, or leave.
- Distinctive: line 317
If the user rejects the proposed commit groups, modify the commit-shaping lane and re-present that lane.
- Distinctive: line 321
Treat "quickly" as a request for a concise preview, not permission to skip safety or collapse all lanes into one action.
- Very specific: line 325
If the user approves both safe and destructive lanes together, execute apply-safe first and pause for a final destructive confirmation …
- Very specific: line 353
If no cleanup branch was created, report Cleanup branch: none.
- Distinctive: line 354
If execution stopped early, replace the completion line with a partial-results summary and list what remains unfinished.
- Distinctive: line 360
run git status only for modes that changed the working tree or created commits
- Very specific: line 363
check git log --oneline <original>..HEAD when commits were created
- Distinctive: line 364
verify only the lane outputs that were actually executed
- Distinctive: line 373
If verification fails, report the mismatch instead of assuming success.
“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Git Hygiene
Clean repo clutter without turning cleanup into data loss or unreadable history. Default to an audit pass, organize findings into independent lanes, and execute only the lanes the user approved.
Quick start
- Verify that the current directory is inside a git repository before doing anything else.
- Abort on complex states such as rebase, merge, cherry-pick, or bisect.
- Default to
auditmode unless the user clearly asked for a specific execution lane. - Organize findings into 4 lanes:
untracked-and-ignorecommit-shapingbranch-pruningconfig-learning
- Never skip preview, even if the user says "just do it."
- Use a reversible deletion mechanism (move-to-trash semantics) for approved file deletions. Never use
rmorgit clean -fd— they are irreversible.
This skill assumes a reversible deletion tool is available. On macOS, install trash via brew install trash. On Linux, install trash-cli (provides trash-put). On GNOME, gio trash is built in. If no reversible tool is available, inspect each file before rm — but a reversible tool is strongly preferred for the recovery property the rest of the skill assumes.
- Create the cleanup branch only for modes that modify the working tree or create commits. Do not create one for audit-only, remote-prune-only, local-branch-delete-only, or no-op runs.
- Do not push, open PRs, rewrite history, or modify submodules.
Modes
Use one of these modes for each run:
| Mode | Purpose | Mutations allowed |
audit | Analyze the repo and propose a lane-based plan. This is the default. | None |
apply-safe | Execute approved reversible or low-risk lanes. | .gitignore updates, commit shaping, remote-tracking prune, optional config update |
apply-destructive | Execute approved destructive actions. | file deletion via reversible mechanism, local branch deletion |
commit-only | Execute only the approved commit-shaping lane. | staging and commits only |
remote-prune-only | Execute only the safe half of branch pruning. | remote-tracking prune only |
local-branch-delete-only | Execute only approved destructive branch cleanup. | local branch deletion only |
If the user asks for "clean up git" without naming a mode, run audit. If the user asks for everything after an audit, execute apply-safe first and apply-destructive only after an extra confirmation gate.
Boundaries and defaults
- Work within one repository at a time.
- Treat submodules as read-only. Report their status, but do not stage, clean, or commit inside them.
- Treat unknown files conservatively. Ask instead of guessing.
- Treat protected-pattern files conservatively. Require explicit per-file confirmation before deleting them.
- If analysis finds nothing worth cleaning, report that the repository is already clean and stop.
- Follow repo-specific branch conventions when they are explicit. Otherwise use
cleanup/YYYY-MM-DD-HHMMSS.
Preconditions and stop conditions
Abort or pause under these conditions:
- Not inside a git repository: stop and tell the user what directory you checked.
- Rebase, merge, cherry-pick, or bisect in progress: stop and tell the user to finish or abort that operation first.
- Shallow clone detected: warn that branch and merge analysis may be incomplete, then ask whether to continue.
- Large repo detected: if more than 100 changed or untracked files or more than 50 local branches are in scope, ask before continuing with full analysis.
Workflow
1. Preflight
Always do preflight first, regardless of mode.
- Verify repo context:
- confirm the repo root
- detect the current branch or detached HEAD
- detect the default branch
- detect worktrees if branch deletion might be proposed later
- Detect complex state:
- if rebase, merge, cherry-pick, or bisect is in progress, abort cleanly
- Check scale:
- count untracked files
- count modified, staged, and unstaged files
- count local branches and stale remote-tracking branches
- if the repo exceeds the large-repo threshold, pause for confirmation
- Load optional config:
- if
.git-hygiene.jsonexists at repo root, load and apply it - if the file is malformed, report that and ignore it for this run
- if
2. Audit
Run audit on the current branch. Do not mutate the repo and do not create the cleanup branch during audit.
Audit produces a structured plan organized into lanes.
Lane: untracked-and-ignore
Classify each untracked file into exactly one category:
ignore candidate: matches known artifact or editor patterns and should usually become an ignore ruletrack candidate: looks like source, config, docs, or test content that probably belongs in version controlask: ambiguous file that needs a user decisionprotected: matches sensitive patterns such as.env*,*.key,*.pem,credentials.*, or repo-specific protected patterns
Rules:
- Never auto-delete
askorprotectedfiles. - Never auto-ignore source-looking files.
- Treat
.gitignoreupdates as infrastructure changes that belong in their own commit. - Separate ignore-rule additions from file deletions in the plan because they have different risk profiles.
Lane: commit-shaping
Analyze staged and unstaged changes together. Use file paths, diff content, and nearby history to propose semantic groups.
For each proposed group:
- assign a short concern label
- list the files involved
- propose a Conventional Commits message
- mark whether the group is safe to apply without destructive steps
- separate infrastructure changes such as
.gitignoreor formatting-only cleanup from feature or bug-fix work
If the user only wants commit hygiene, this lane can run independently.
Lane: branch-pruning
Propose candidates in 2 sub-lanes with different risk levels:
remote-prune: remote-tracking branches whose upstream is gonelocal-branch-delete: local branches fully merged into the default branch
Before proposing branch deletion:
- check whether the branch is checked out in another worktree
- exclude the current branch, default branch, and repo-protected branches
- keep local branch deletion and remote-tracking prune separate in both preview and approval because the former is destructive and the latter is low risk
Lane: config-learning
Summarize reusable patterns worth saving to .git-hygiene.json, such as:
- ignore patterns the user approved
- protected patterns the user extended
- grouping hints that clearly improved commit shaping
- branch-protection rules the user clarified
Treat this lane as optional. Do not write config changes unless the user approves them.
3. Preview
Present the audit output as a lane-based plan. Use this shape:
Mode: audit
Lane: untracked-and-ignore
.gitignore additions:
+ *.pyc
+ __pycache__/
Files to delete (reversible):
- tmp/debug.log
Unknown files:
? notes.md - track, ignore, delete, or leave
Protected files:
! credentials.local.json - delete only with explicit per-file confirmation
Lane: commit-shaping
1. chore: update .gitignore with Python artifacts
2. fix(auth): validate token expiration before refresh
3. style(api): apply consistent formatting
Lane: branch-pruning
Remote tracking to prune:
- origin/feature/deleted-upstream
Local branches to delete:
- feature/old-experiment
Lane: config-learning
Proposed saved patterns:
+ ignorePatterns: ["*.pyc", "__pycache__/"]If the user says "skip preview" or "just do it," shorten the preview but still show the lane summary and ask for confirmation.
4. Collect decisions
Collect approvals lane by lane.
For untracked-and-ignore:
- each
askfile:track,ignore,delete, orleave - each protected file proposed for deletion
- whether ignore-rule changes should be committed now or only proposed
For commit-shaping:
- split, merge, reassign, rename, drop, or approve each group
For branch-pruning:
- approve local branch deletions separately from remote prune operations
For config-learning:
- approve, edit, or decline proposed
.git-hygiene.jsonupdates
If the user changes any lane materially, regenerate the preview for that lane and reconfirm before execution.
5. Lane dependencies
Resolve lane dependencies before choosing an execution mode.
untracked-and-ignore -> commit-shapingwhen file decisions change which files should be committed, ignored, or deleted.commit-shapingmust run after any approved.gitignorecommit when both are in scope.remote-pruneis independent of the other lanes and can run on its own.local-branch-deleteis independent of commit shaping, but it still requires destructive approval.config-learningruns last because it depends on what the user actually approved in the other lanes.
6. Execute by mode
audit
- Do not mutate anything.
- End with the lane-based plan and the recommended next mode.
apply-safe
Execute only approved non-destructive or lower-risk actions:
- Resolve lane dependencies first.
- Create the cleanup branch only if approved safe work will modify the working tree or create commits.
- Create one for
.gitignorechanges, commit-shaping, or repo-root config changes that the user wants isolated. - Do not create one for remote prune alone.
- Create one for
- Apply
.gitignoreupdates and commit them first. - Stage and commit approved
commit-shapinggroups. - Prune approved remote-tracking branches.
- Write approved
.git-hygiene.jsonupdates if the user wanted them.
Do not delete files or local branches in this mode.
apply-destructive
Require an extra confirmation gate before starting.
Execute only approved destructive actions:
- Resolve lane dependencies first.
- Create the cleanup branch only if approved file deletions should be isolated in the working tree.
- Do not create one for local branch deletion alone.
- Delete approved files using a reversible mechanism (e.g.,
trashon macOS,trash-puton Linux,gio trashon GNOME).- Default: do not stage or commit those deletions in this mode.
- Leave the deleted files as explicit working-tree changes unless the user later runs
commit-onlyorapply-safewith an approved commit group that captures them.
- Delete approved local branches that are safe to delete and not active in any worktree.
Do not smuggle in unrelated safe actions here. This mode is for destructive work only. Do not create commits or stage deletions in this mode.
commit-only
- Resolve lane dependencies first.
- Confirm that any file decisions from
untracked-and-ignorethat affect commits are already settled. - Create the cleanup branch if commit creation should be isolated.
- Stage each approved change group.
- Create each approved commit with the approved Conventional Commits message.
Do not modify untracked-file decisions or branch state outside what the commit lane explicitly needs.
remote-prune-only
- Prune approved remote-tracking branches.
Do not create a cleanup branch, create commits, or edit .gitignore in this mode.
local-branch-delete-only
Require an extra confirmation gate before starting.
- Delete approved local branches that passed the worktree and protection checks.
Do not create a cleanup branch, create commits, or edit .gitignore in this mode.
7. Failure handling
Stop immediately on any failure. Report:
- the current mode
- the lane being executed
- what succeeded
- what failed
- the exact command or operation that failed
- what remains unattempted
Do not guess, continue, or rollback automatically.
Non-negotiables
- Never skip preview.
- Never delete files without explicit approval.
- Never delete protected files from batch approval alone.
- Never use
rmorgit clean -fd; use a reversible deletion mechanism (e.g.,trash,trash-put,gio trash) for filesystem deletion. - Never collapse unrelated changes into one "cleanup" commit without first proposing better grouping.
- Never delete branches without checking worktree usage.
- Never create cleanup branches for audit-only or no-op runs.
- Never mix destructive and non-destructive execution behind one vague approval.
- Never treat remote prune approval as approval to delete local branches.
Decision rules
Default mode
If the user did not explicitly choose a mode, use audit.
Unknown files
Ask per file: track, ignore, delete, or leave. If the user gives a risky batch instruction, restate the affected files before acting.
Protected file deletion
Require explicit per-file confirmation separate from the main plan approval. Name the matched protection reason in the confirmation line.
Grouping disagreement
If the user rejects the proposed commit groups, modify the commit-shaping lane and re-present that lane. Do not improvise silently.
Impatience or pressure
Treat "quickly" as a request for a concise preview, not permission to skip safety or collapse all lanes into one action.
Destructive actions
If the user approves both safe and destructive lanes together, execute apply-safe first and pause for a final destructive confirmation before apply-destructive.
Report format
End with a mode-aware summary in this shape:
Mode completed: apply-safe
Cleanup branch: cleanup/2026-03-20-143052
Lane results:
untracked-and-ignore:
.gitignore patterns added: 3
files deleted (reversible): 0
commit-shaping:
commits created: 4
abc1234 chore: update .gitignore with Python artifacts
def5678 feat(config): add new-feature configuration
branch-pruning:
local branches deleted: 0
remote tracking pruned: 1
config-learning:
config updated: no
Recommended next step:
apply-destructive for approved file or local-branch deletionsIf no cleanup branch was created, report Cleanup branch: none.
If execution stopped early, replace the completion line with a partial-results summary and list what remains unfinished.
Verification
After execution:
- run
git statusonly for modes that changed the working tree or created commits - expect a clean working tree after
apply-safeorcommit-onlyunless the user explicitly chose to leave files uncommitted - expect a dirty working tree after
apply-destructivewhen file deletions were performed without a follow-up commit; report that state as intentional - check
git log --oneline <original>..HEADwhen commits were created - verify only the lane outputs that were actually executed
Examples:
commit-shapingexecuted: verify created commitsremote-prune-onlyexecuted: verify approved remote-tracking refs are gonelocal-branch-delete-onlyexecuted: verify approved local branches are goneuntracked-and-ignoreexecuted destructively: verify deleted files are gone and note whether the resulting worktree changes are intentionally uncommitted
If verification fails, report the mismatch instead of assuming success.
Anti-patterns
| Pattern | Problem | Fix |
| Treating all hygiene work as one big operation | It couples unrelated risks and makes approval too broad. | Split the plan into lanes and execute only approved lanes. |
| Using one branch-cleanup approval for both remote prune and local deletion | It blurs low-risk and destructive work. | Approve remote-prune and local-branch-delete separately. |
Running git add . and making one cleanup commit | It destroys commit coherence and makes history harder to review, revert, or cherry-pick. | Propose semantic groups first. |
Running git clean -fd because the repo looks messy | It turns cleanup into irreversible deletion. | Preview first and use a reversible deletion mechanism only for explicitly approved files. |
| Treating user impatience as informed consent | "Just do it" does not waive safety requirements. | Keep the preview concise, but do not skip it. |
Mixing .gitignore changes with code changes | It muddies history and makes review harder. | Commit .gitignore changes separately and first. |
| Deleting branches without a worktree check | A branch may be active elsewhere. | Check worktrees before proposing deletion. |
| Creating a cleanup branch before confirming there is real work | It leaves no-op branches behind. | Audit first, branch later. |
Example
User: "Clean up this repo. I have random untracked files, mixed auth work, and old merged branches."
- Run
audit. - Present the plan by lane:
untracked-and-ignorecommit-shapingbranch-pruningconfig-learning
- Collect approvals per lane and resolve dependencies.
- Execute
apply-safefor approved.gitignore, commit-shaping, remote prune, and config updates. - Pause for a final confirmation before
apply-destructiveif approved file deletions or local branch deletions remain. - Report lane-by-lane results and the next recommended mode.
Reference
Read references/git-hygiene-config.md when:
.git-hygiene.jsonexists and you need to interpret it- the user wants to customize ignore, protection, or grouping behavior
- branch-protection or commit-prefix defaults need explanation
Other versions3 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 3
- adamentwistle/fable-skills★ 98same name
- wolf5996/agentic-skills★ 10same name
- neeraj181-dot/ClaudeSkills★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository5 other files it gives its agents.
- making-recommendationsSkill
- next-stepsSkill
- scrutinizeSkill
- system-design-reviewSkill
- writing-principlesSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

