AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Git Housekeeping

skill-rolecraft-sh-skills-git-housekeeping · by rolecraft-sh

Clean up local git branches, detect stale branches, manage stashes, and lint commit messages. Use when the user says 'cleanup branches', 'tidy git', 'remove merged branches', 'git housekeeping', 'stale branches', or wants to clean up local git state.

No reviews yet
0 installs
14 views
0.0% view→install

Install

$ agentstack add skill-rolecraft-sh-skills-git-housekeeping

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-rolecraft-sh-skills-git-housekeeping)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
1mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Git Housekeeping? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Git Housekeeping

Keep your local git repositories tidy. This skill analyzes your git state, identifies branches that can be safely removed, checks for common git hygiene issues, and executes cleanup — always with user confirmation before any destructive action.

Safety Rules (NEVER VIOLATE)

  1. NEVER delete the current checked-out branch.
  2. NEVER delete main, master, develop, or trunk.
  3. NEVER delete a branch with unpushed commits without explicit warning.
  4. ALWAYS present a dry-run plan before executing any deletion.
  5. ALWAYS ask for confirmation before running destructive commands.
  6. NEVER force push or rewrite history.
  7. ALWAYS run git fetch --prune first to get accurate remote state.

Phases

Phase 1: Fetch and Analyze

Run these commands to gather the full state:

# Fetch latest remote state
git fetch --prune

# List all local branches
git branch

# Show current branch
git branch --show-current

# Check for uncommitted changes
git status --short

# List stashes
git stash list

# Show default branch
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@'

Identify:

  • Default branch — usually main or master (from origin/HEAD)
  • Current branch — never touch this one
  • Protected branchesmain, master, develop, trunk

Phase 2: Find Merged Branches

Find branches that have been merged into the default branch:

git branch --merged  | grep -vE '^\*|^\s*(main|master|develop|trunk)$'

These are safe to delete with git branch -d.

Important: Squash-merges may hide merged branches from --merged. Cross-check with git log --oneline .. — if empty (no unique commits), the branch work is already in the default branch even if --merged doesn't show it.

Phase 3: Find Stale Branches

Find branches with no commits in the last 30 days:

git for-each-ref --sort=-committerdate refs/heads/ \
  --format='%(committerdate:relative)||%(refname:short)' \
  | head -20

Flag branches older than 30 days that are NOT in the merged list. Ask before listing them as stale candidates.

Phase 4: Check Hygiene

Run these checks and report issues:

# Check stash count
stash_count=$(git stash list 2>/dev/null | wc -l)

# Check uncommitted changes
dirty_count=$(git status --short | wc -l)

# Check for merge conflicts
conflict_count=$(git diff --name-only --diff-filter=U 2>/dev/null | wc -l)

# Check remote tracking branches with deleted upstream
gone_count=$(git branch -vv | grep ': gone]' | wc -l)

Report:

  • Stashes: if > 3, suggest review
  • Dirty files: if any, warn that cleanup won't touch them
  • Conflicts: if any, flag as blockers
  • Gone branches: branches whose remote was deleted — offer to prune

Phase 5: Present Full Report

Present a structured report:

## Git Housekeeping Report

### Merge Status
- Default branch: `main`
- Current branch: `feat/my-feature` (will NOT be touched)
- Protected: `main`, `master`, `develop`, `trunk`

### Safe to Delete (merged into default)
- `fix/typo` — merged into main
- `feat/login` — squash-merged, no unique commits
- `chore/update-deps` — merged into main

### Stale Candidates (30+ days, not merged)
- `experiment/new-api` — last commit 45 days ago
- `old-refactor` — last commit 60 days ago
    ↳ Ask user before including in delete list

### Hygiene
- ✅ Stashes: 1
- ⚠️ Dirty files: 2 (unrelated to cleanup)
- ✅ Merge conflicts: 0
- ℹ️ Gone branches: 3 (remote deleted)

### Summary
- 3 branches safe to delete
- 2 stale candidates (ask)
- 3 gone branches to prune

Proceed with cleanup? (y/N)

Phase 6: Execute Cleanup

Only after user confirms:

# Delete merged branches (safe delete)
git branch -d fix/typo
git branch -d feat/login
git branch -d chore/update-deps

# Delete gone branches (remote deleted, local tracking refs)
git branch -d old-feature
git branch -d wip-experiment

# Prune remote tracking refs
git remote prune origin

# Print remaining branches
git branch

Force delete (-D) only for squash-merged branches where -d fails, and only after telling the user why force is needed.

Phase 7: Verify

git branch
git stash list
git status --short

Report what was cleaned up and what remains.

Anti-Patterns

| Anti-pattern | Why | Instead | |---|---|---| | git branch -D without checking | Deletes unmerged work | Always try -d first | | git clean -fd without review | Destroys untracked files | Use git clean -n (dry-run) first | | Deleting remote branches | Affects the whole team | Only delete local branches | | git push --force | Rewrites history | Never part of cleanup |

Examples

User: "clean up my branches"

Agent:

  1. Runs git fetch --prune and git branch --merged main
  2. Finds 4 merged branches, 1 stale branch, 2 gone branches
  3. Shows report with exact git branch -d commands
  4. Asks: "Delete 4 merged branches? (y/N)"
  5. User confirms → deletes them
  6. Shows remaining branches

User: "tidy up this repo"

Agent:

  1. Full analysis: merged, stale, hygiene
  2. Finds 0 merged but 8 gone branches, 5 stashes
  3. Reports: "No merged branches. 8 remote-tracking refs have gone upstream.

5 stashes — want to review them?"

  1. Prunes gone refs after user confirms

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.