agentleFS
jpsweeney97jpsweeney97/claude-code-skills/skills/git-hygiene/SKILL.md

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
  1. Distinctive:

    Verify that the current directory is inside a git repository before doing anything else.

    line 12
  2. Very specific:

    Default to audit mode unless the user clearly asked for a specific execution lane.

    line 14
  3. Distinctive:

    Never skip preview, even if the user says "just do it."

    line 20
  4. Very specific:

    Use a reversible deletion mechanism (move-to-trash semantics) for approved file deletions.

    line 21
  5. Distinctive:

    Create the cleanup branch only for modes that modify the working tree or create commits.

    line 25
  6. Distinctive:

    Do not push, open PRs, rewrite history, or modify submodules.

    line 26
  7. Distinctive:

    Use one of these modes for each run:

    line 30
  8. Very specific:

    If the user asks for "clean up git" without naming a mode, run audit.

    line 41
  9. Distinctive:

    Treat submodules as read-only.

    line 46
  10. Distinctive:

    Treat unknown files conservatively.

    line 47
  11. Distinctive:

    Treat protected-pattern files conservatively.

    line 48
  12. Distinctive:

    If analysis finds nothing worth cleaning, report that the repository is already clean and stop.

    line 49
  13. Very specific:

    Follow repo-specific branch conventions when they are explicit.

    line 50
  14. Distinctive:

    Not inside a git repository: stop and tell the user what directory you checked.

    line 56
  15. Distinctive:

    Always do preflight first, regardless of mode.

    line 65
  16. Distinctive:

    if rebase, merge, cherry-pick, or bisect is in progress, abort cleanly

    line 73
  17. Distinctive:

    if the repo exceeds the large-repo threshold, pause for confirmation

    line 78
  18. Very specific:

    if .git-hygiene.json exists at repo root, load and apply it

    line 80
  19. Distinctive:

    if the file is malformed, report that and ignore it for this run

    line 81
  20. Distinctive:

    Run audit on the current branch.

    line 85
  21. Very specific:

    Never auto-delete ask or protected files.

    line 100
  22. Distinctive:

    Never auto-ignore source-looking files.

    line 101
  23. Very specific:

    Treat .gitignore updates as infrastructure changes that belong in their own commit.

    line 102
  24. Distinctive:

    If the user only wants commit hygiene, this lane can run independently.

    line 117
  25. Distinctive:

    Before proposing branch deletion:

    line 126
  26. Distinctive:

    check whether the branch is checked out in another worktree

    line 128
  27. Distinctive:

    keep local branch deletion and remote-tracking prune separate in both preview and approval because the former is destructive and the latter …

    line 130
  28. Distinctive:

    Treat this lane as optional.

    line 141
  29. Distinctive:

    If the user says "skip preview" or "just do it," shorten the preview but still show the lane summary and ask for confirmation.

    line 177
  30. Distinctive:

    If the user changes any lane materially, regenerate the preview for that lane and reconfirm before execution.

    line 201
  31. Distinctive:

    Do not mutate anything.

    line 217
  32. Distinctive:

    Create the cleanup branch only if approved safe work will modify the working tree or create commits.

    line 225
  33. Very specific:

    Create one for .gitignore changes, commit-shaping, or repo-root config changes that the user wants isolated.

    line 226
  34. Distinctive:

    Do not create one for remote prune alone.

    line 227
  35. Very specific:

    Write approved .git-hygiene.json updates if the user wanted them.

    line 231
  36. Distinctive:

    Do not delete files or local branches in this mode.

    line 233
  37. Distinctive:

    Create the cleanup branch only if approved file deletions should be isolated in the working tree.

    line 242
  38. Distinctive:

    Do not create one for local branch deletion alone.

    line 243
  39. Very specific:

    Delete approved files using a reversible mechanism (e.g., trash on macOS, trash-put on Linux, gio trash on GNOME).

    line 244
  40. Distinctive:

    Default: do not stage or commit those deletions in this mode.

    line 245
  41. Very specific:

    Leave the deleted files as explicit working-tree changes unless the user later runs commit-only or apply-safe with an approved commit group …

    line 246
  42. Distinctive:

    Delete approved local branches that are safe to delete and not active in any worktree.

    line 247
  43. Distinctive:

    Do not smuggle in unrelated safe actions here.

    line 249
  44. Distinctive:

    Do not create commits or stage deletions in this mode.

    line 250
  45. Distinctive:

    Create the cleanup branch if commit creation should be isolated.

    line 256
  46. Distinctive:

    Create each approved commit with the approved Conventional Commits message.

    line 258
  47. Distinctive:

    Do not modify untracked-file decisions or branch state outside what the commit lane explicitly needs.

    line 260
  48. Very specific:

    Do not create a cleanup branch, create commits, or edit .gitignore in this mode.

    line 266
  49. Distinctive:

    Delete approved local branches that passed the worktree and protection checks.

    line 272
  50. Distinctive:

    Stop immediately on any failure.

    line 278
  51. Distinctive:

    Do not guess, continue, or rollback automatically.

    line 287
  52. Distinctive:

    Never delete files without explicit approval.

    line 292
  53. Distinctive:

    Never delete protected files from batch approval alone.

    line 293
  54. Very specific:

    Never use rm or git clean -fd.

    line 294
  55. Distinctive:

    Never collapse unrelated changes into one "cleanup" commit without first proposing better grouping.

    line 295
  56. Distinctive:

    Never delete branches without checking worktree usage.

    line 296
  57. Distinctive:

    Never create cleanup branches for audit-only or no-op runs.

    line 297
  58. Distinctive:

    Never mix destructive and non-destructive execution behind one vague approval.

    line 298
  59. Distinctive:

    Never treat remote prune approval as approval to delete local branches.

    line 299
  60. Very specific:

    If the user did not explicitly choose a mode, use audit.

    line 305
  61. Very specific:

    Ask per file: track, ignore, delete, or leave.

    line 309
  62. Distinctive:

    If the user rejects the proposed commit groups, modify the commit-shaping lane and re-present that lane.

    line 317
  63. Distinctive:

    Treat "quickly" as a request for a concise preview, not permission to skip safety or collapse all lanes into one action.

    line 321
  64. Very specific:

    If the user approves both safe and destructive lanes together, execute apply-safe first and pause for a final destructive confirmation …

    line 325
  65. Very specific:

    If no cleanup branch was created, report Cleanup branch: none.

    line 353
  66. Distinctive:

    If execution stopped early, replace the completion line with a partial-results summary and list what remains unfinished.

    line 354
  67. Distinctive:

    run git status only for modes that changed the working tree or created commits

    line 360
  68. Very specific:

    check git log --oneline <original>..HEAD when commits were created

    line 363
  69. Distinctive:

    verify only the lane outputs that were actually executed

    line 364
  70. Distinctive:

    If verification fails, report the mismatch instead of assuming success.

    line 373

“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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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 audit mode unless the user clearly asked for a specific execution lane.
  • Organize findings into 4 lanes:
    • untracked-and-ignore
    • commit-shaping
    • branch-pruning
    • config-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 rm or git 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:

ModePurposeMutations allowed
auditAnalyze the repo and propose a lane-based plan. This is the default.None
apply-safeExecute approved reversible or low-risk lanes..gitignore updates, commit shaping, remote-tracking prune, optional config update
apply-destructiveExecute approved destructive actions.file deletion via reversible mechanism, local branch deletion
commit-onlyExecute only the approved commit-shaping lane.staging and commits only
remote-prune-onlyExecute only the safe half of branch pruning.remote-tracking prune only
local-branch-delete-onlyExecute 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.

  1. 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
  2. Detect complex state:
    • if rebase, merge, cherry-pick, or bisect is in progress, abort cleanly
  3. 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
  4. Load optional config:
    • if .git-hygiene.json exists at repo root, load and apply it
    • if the file is malformed, report that and ignore it for this run

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 rule
  • track candidate: looks like source, config, docs, or test content that probably belongs in version control
  • ask: ambiguous file that needs a user decision
  • protected: matches sensitive patterns such as .env*, *.key, *.pem, credentials.*, or repo-specific protected patterns

Rules:

  • Never auto-delete ask or protected files.
  • Never auto-ignore source-looking files.
  • Treat .gitignore updates 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 .gitignore or 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 gone
  • local-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 ask file: track, ignore, delete, or leave
  • 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.json updates

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-shaping when file decisions change which files should be committed, ignored, or deleted.
  • commit-shaping must run after any approved .gitignore commit when both are in scope.
  • remote-prune is independent of the other lanes and can run on its own.
  • local-branch-delete is independent of commit shaping, but it still requires destructive approval.
  • config-learning runs 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:

  1. Resolve lane dependencies first.
  2. Create the cleanup branch only if approved safe work will modify the working tree or create commits.
    • Create one for .gitignore changes, commit-shaping, or repo-root config changes that the user wants isolated.
    • Do not create one for remote prune alone.
  3. Apply .gitignore updates and commit them first.
  4. Stage and commit approved commit-shaping groups.
  5. Prune approved remote-tracking branches.
  6. Write approved .git-hygiene.json updates 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:

  1. Resolve lane dependencies first.
  2. 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.
  3. Delete approved files using a reversible mechanism (e.g., trash on macOS, trash-put on Linux, gio trash on 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-only or apply-safe with an approved commit group that captures them.
  4. 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

  1. Resolve lane dependencies first.
  2. Confirm that any file decisions from untracked-and-ignore that affect commits are already settled.
  3. Create the cleanup branch if commit creation should be isolated.
  4. Stage each approved change group.
  5. 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

  1. 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.

  1. 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 rm or git 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 deletions

If 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 status only for modes that changed the working tree or created commits
  • expect a clean working tree after apply-safe or commit-only unless the user explicitly chose to leave files uncommitted
  • expect a dirty working tree after apply-destructive when file deletions were performed without a follow-up commit; report that state as intentional
  • check git log --oneline <original>..HEAD when commits were created
  • verify only the lane outputs that were actually executed

Examples:

  • commit-shaping executed: verify created commits
  • remote-prune-only executed: verify approved remote-tracking refs are gone
  • local-branch-delete-only executed: verify approved local branches are gone
  • untracked-and-ignore executed 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

PatternProblemFix
Treating all hygiene work as one big operationIt 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 deletionIt blurs low-risk and destructive work.Approve remote-prune and local-branch-delete separately.
Running git add . and making one cleanup commitIt 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 messyIt 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 changesIt muddies history and makes review harder.Commit .gitignore changes separately and first.
Deleting branches without a worktree checkA branch may be active elsewhere.Check worktrees before proposing deletion.
Creating a cleanup branch before confirming there is real workIt 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."

  1. Run audit.
  2. Present the plan by lane:
    • untracked-and-ignore
    • commit-shaping
    • branch-pruning
    • config-learning
  3. Collect approvals per lane and resolve dependencies.
  4. Execute apply-safe for approved .gitignore, commit-shaping, remote prune, and config updates.
  5. Pause for a final confirmation before apply-destructive if approved file deletions or local branch deletions remain.
  6. Report lane-by-lane results and the next recommended mode.

Reference

Read references/git-hygiene-config.md when:

  • .git-hygiene.json exists and you need to interpret it
  • the user wants to customize ignore, protection, or grouping behavior
  • branch-protection or commit-prefix defaults need explanation

Download now (ZIP)

  • Other versions3 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 3

    1. adamentwistle/fable-skills★ 98same name
    2. wolf5996/agentic-skills★ 10same name
    3. 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.

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.