---
name: git-branching-analyzer
description: "Reports on a repository's branch health in a form you can act on: stale and unmerged branches, how far each is ahead or behind main, naming violations, and the cleanup commands to run, in Markdown, JSON, or plain text. Use when a repository has accumulated branches and someone wants to know which are stale, unmerged, diverged, or misnamed, and what to delete or rebase. Do not use for designing a branching strategy, resolving merge conflicts, or rewriting commit history. Related topics: coding, git."
---

# Git Branching Analyzer

Reports on a repository's branch health in a form you can act on: stale and unmerged branches, how far each is ahead or behind main, naming violations, and the cleanup commands to run, in Markdown, JSON, or plain text.

## When to use

Use this skill when a repository has accumulated branches and someone wants to know which are stale, unmerged, diverged, or misnamed, and what to delete or rebase. Do not use it for designing a branching strategy, resolving merge conflicts, or rewriting commit history.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Use the supplied branch listing, or give the git commands that produce it and base the report on the pasted result.
3. Classify every branch as merged, stale, diverged, active, or protected using the stale window and analysis depth.
4. Check each name against the convention and list violators with a compliant name.
5. Assign an action per branch (delete, confirm with owner, rebase or merge, rename) with the constraint that applies.
6. Produce the report in the selected format with counts, the stale list, the ahead and behind table, violations, and cleanup commands ordered with destructive ones last.

## Inputs

- **Repository path** (free text, e.g. "/path/to/repo")
- **Main branch name** (free text, e.g. "main")
- **Branch listing** (longer free text)
- **Include merged branches** (choose one: Yes, No)
- **Analysis depth (commits)** (number from 100 to 1000)
- **Stale after (days)** (number from 7 to 365)
- **Branch naming convention** (choose one: feature/*, bugfix/*, hotfix/*, release/*, type/ticket-description, custom)
- **Output format** (choose one: Markdown, JSON, Plain text)

## Output

A report in the chosen format containing total branch count, counts per class, the stale branch list with date and author, an ahead and behind table against main, naming violations, and ordered cleanup commands with destructive steps marked.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Git Branching Analyzer

Analyse the branch structure of this repository and recommend a cleanup.

- Repository path: {{Repository path}}
- Main branch name: {{Main branch name}}
- Branch listing: {{Branch listing}}
- Include merged branches: {{Include merged branches}}
- Analysis depth (commits): {{Analysis depth (commits)}}
- Stale after (days): {{Stale after (days)}}
- Branch naming convention: {{Branch naming convention}}
- Output format: {{Output format}}

Work from the branch listing when it is supplied; when it is not, give the exact git commands (for-each-ref with committerdate, rev-list --left-right --count against main, branch --merged) that produce it and base the report on what the user pastes back. Classify each branch: merged into main, stale (no commit within the stale window), diverged (ahead and behind main by more than the depth allows a clean rebase), active, and protected (main, release branches). Check every name against the convention and list the violators with the name that would comply. Recommend actions per branch: delete merged branches locally and on the remote, ask the owner about stale unmerged ones before deleting, rebase or merge diverged active ones, and rename violators only when no open pull request references them. Give the report in the selected format with: total branch count, counts per class, the stale list with last commit date and author, the ahead and behind table, naming violations, and the cleanup commands in the order to run them, with the destructive ones last and clearly marked.

## Pitfalls

- Deleting an unmerged stale branch because it is old; the owner may hold the only copy of that work.
- Measuring staleness by branch creation date instead of last commit date, which flags long-lived active branches.
- Renaming a branch that an open pull request points at, which closes the PR on most hosting platforms.
