home / skills / codyswanngt / lisa / git-prune

git-prune skill

/.claude/skills/git-prune

This skill prunes local git branches that track deleted remotes by safely previewing, deleting only merged branches, and reporting results.

npx playbooks add skill codyswanngt/lisa --skill git-prune

Review the files below or copy the command above to add this skill to your agents.

Files (1)
SKILL.md
935 B
---
name: git-prune
description: This skill should be used when pruning local branches that have been deleted on the remote. It fetches remote changes, identifies stale local branches, and safely deletes them.
allowed-tools: ["Bash"]
---

# Git Prune Local Branches

Remove local branches whose upstream tracking branches have been deleted on remote.

## Workflow

### Fetch and prune remote-tracking references

!git fetch --prune

### Find and delete stale local branches

!git branch -vv | grep ': gone]' | awk '{print $1}'

### Apply these requirements

1. **Preview**: Show which branches will be deleted before deleting
2. **Safe Delete**: Use `-d` (safe delete) which refuses to delete unmerged branches
3. **Report**: Show summary of deleted branches

### Never

- Force delete (`-D`) without user confirmation
- Delete the current branch
- Delete protected branches (dev, staging, main)

## Execute

Execute the workflow now.

Overview

This skill helps safely prune local Git branches that track remote branches removed on the remote. It fetches remote updates, identifies local branches whose upstreams are gone, previews them, and performs safe deletions while protecting important branches. The skill reports what was deleted and preserves unmerged work.

How this skill works

First it runs git fetch --prune to update remote-tracking refs. Then it scans local branches with git branch -vv to find entries marked ': gone]' and lists those branch names. It prompts for a preview, deletes branches using git branch -d (safe delete) while skipping the current branch and protected names, and finally prints a summary of deleted and retained branches.

When to use it

  • After remote branches are deleted and you want to clean local clones
  • Periodically to keep local branch list manageable
  • Before switching to a new release or feature to remove stale branches
  • When preparing a developer environment for onboarding or handoff

Best practices

  • Always run git fetch --prune before scanning to ensure up-to-date information
  • Preview the list of candidate branches and verify no active work is lost
  • Use git branch -d to avoid deleting branches with unmerged commits
  • Do not delete the current branch; switch to a safe branch first
  • Protect key branches such as dev, staging, and main from deletion without explicit override

Example use cases

  • Remove local branches after a remote cleanup to reduce clutter
  • Clean stale feature branches before opening a release branch
  • Automate routine maintenance in a developer workstation setup script
  • Run during CI workspace reset to keep clones lean

FAQ

Will this delete branches with unmerged commits?

No. The skill uses safe delete (git branch -d) which refuses to delete branches that contain commits not merged into the configured upstream or HEAD.

How does it protect important branches?

It skips deletion for the current branch and for configured protected names such as dev, staging, and main. You can extend the protected list before running if you need more safeguards.