# Git post merge cleanup

> Git post merge cleanup is an open-source agent skill for developer tools. Cleans merged branches, gone remote refs and finished worktrees after PRs land. It is available on Claude Code.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code
- **Website:** https://github.com/ivy00johns/Skill-Madness/tree/main/skills/git/git-post-merge-cleanup
- **Repository:** https://github.com/ivy00johns/skill-madness
- **GitHub stars:** 12
- **License:** MIT
- **Skill name:** git-post-merge-cleanup
- **Collection:** https://github.com/ivy00johns/Skill-Madness
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-03

## About

This skill tidies a local git repository after a batch of pull requests has been merged. It looks for three kinds of leftover state: local branches already merged into the default branch, remote-tracking references whose remote branch was deleted, and secondary worktrees whose changes already exist on the main branch. The agent scans and classifies everything first, then shows a single plan grouped by category.

The workflow is built around safety. Scans are read-only, and the agent only deletes after the user confirms, or after an explicit --yes flag or a --dry-run preview. Branches with unmerged work and worktrees with genuinely unmerged changes are flagged for attention rather than touched. Tags are handled separately: they are only deleted when the owner has approved a disposable retention policy, and remote tag deletion needs separate authorization.

The skill relies on a set of reference files for edge cases such as squash-merged branches and worktree detection. It expects a git repository with an origin remote, and it uses standard git commands through Bash.

## When your agent uses it

> Clean up stale git state after merges in one pass: merged local branches, tracking refs whose remote is gone, and worktrees that look modified but are already on main. Scans, shows a plan, acts only on confirmation; supports --dry-run and --yes. Use after a batch of PRs lands. Trigger on "clean up branches", "prune branches", "stale branches", "clean up worktrees".

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/ivy00johns/Skill-Madness/tree/HEAD/skills/git/git-post-merge-cleanup)
- [Asks for: Bash, Read, Write](https://github.com/ivy00johns/Skill-Madness/blob/HEAD/skills/git/git-post-merge-cleanup/SKILL.md)
- [License: MIT](https://github.com/ivy00johns/Skill-Madness/tree/HEAD/skills/git/git-post-merge-cleanup)

## Features

- **Merged branch detection:** Finds local and remote branches already merged into the default branch.
- **Gone tracking reference cleanup:** Identifies tracking references whose remote branch was removed after merge.
- **Worktree safety classification:** Separates worktrees whose changes already landed on main from those with unmerged work.
- **Confirmation before deletion:** Presents one combined plan and waits for approval before running destructive commands.
- **Dry-run and auto-confirm flags:** Supports a preview-only mode and a non-interactive mode that still prints the plan.
- **Protected tag handling:** Keeps release and unknown-policy tags and requires explicit approval for tag deletion.

## Good for

- Clean up branches after a batch of pull requests has been merged
- Remove worktrees whose changes already landed on main
- Preview which stale branches would be deleted without changing anything
- Prune remote-tracking references for branches deleted on GitHub

## Install

### Claude Code

This skill ships in the `skill-madness` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add ivy00johns/Skill-Madness
/plugin install skill-madness@skill-madness
```

Or copy only this skill to `~/.claude/skills/git-post-merge-cleanup`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/git-post-merge-cleanup &&
cp -R "$tmp/skills/git/git-post-merge-cleanup" ~/.claude/skills/git-post-merge-cleanup &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/git-post-merge-cleanup` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/git-post-merge-cleanup` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/git-post-merge-cleanup &&
cp -R "$tmp/skills/git/git-post-merge-cleanup" ~/.agents/skills/git-post-merge-cleanup &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/git-post-merge-cleanup` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/git-post-merge-cleanup` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/git-post-merge-cleanup &&
cp -R "$tmp/skills/git/git-post-merge-cleanup" ~/.cursor/skills/git-post-merge-cleanup &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/git-post-merge-cleanup` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/ivy00johns/Skill-Madness.git --path skills/git/git-post-merge-cleanup
```

Or copy the folder to `~/.gemini/skills/git-post-merge-cleanup` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/git-post-merge-cleanup`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/git-post-merge-cleanup &&
cp -R "$tmp/skills/git/git-post-merge-cleanup" ~/.copilot/skills/git-post-merge-cleanup &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/git-post-merge-cleanup` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/ivy00johns/Skill-Madness.git
```

Then copy `Skill-Madness/skills/git/git-post-merge-cleanup` into your agent's skills folder as `git-post-merge-cleanup`. Agents that support SKILL.md read one folder per skill.

## FAQ

### What triggers Git post merge cleanup?

Requests such as clean up branches, prune branches, stale branches or clean up worktrees, typically after PRs land.

### Does Git post merge cleanup delete anything without asking?

By default no. It shows a plan and waits for confirmation. --dry-run stops after the plan, and --yes skips the prompt but still prints the plan first.

### Will Git post merge cleanup remove the main worktree or the default branch?

No. The main worktree and the default branch, along with develop, staging and production, are excluded by its safety rules.

### Does Git post merge cleanup delete tags?

Only tags the owner has approved as disposable. Release, signed and unknown-policy tags are kept, and remote tag deletion needs explicit authorization.

### How do I install Git post merge cleanup in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/git-post-merge-cleanup to use it in all your projects, or to .claude/skills/git-post-merge-cleanup in one project. Or install the skill-madness plugin, which includes it: /plugin marketplace add ivy00johns/Skill-Madness, then /plugin install skill-madness@skill-madness.

### Does Git post merge cleanup run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Git post merge cleanup?

Claude Code. It reads skills in the SKILL.md format; the install steps on this page show where to put the folder.

### What are the best alternatives to Git post merge cleanup?

The closest alternatives to Git post merge cleanup are Git branch cleanup, Git clean worktrees, Merge PR, Gh PR merge worktree checkout trap and Fix merge conflicts.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Git branch cleanup](https://ai-powered.com/skills/git-branch-cleanup): Git branch cleanup is an open-source agent skill for developer tools.
- [Git clean worktrees](https://ai-powered.com/skills/git-clean-worktrees): Git clean worktrees is an open-source agent skill for developer tools.
- [Merge PR](https://ai-powered.com/skills/merge-pr): Merge PR is an open-source agent skill for developer tools.
- [Gh PR merge worktree checkout trap](https://ai-powered.com/skills/gh-pr-merge-worktree-checkout-trap): Gh PR merge worktree checkout trap is an open-source agent skill for developer tools.
- [Fix merge conflicts](https://ai-powered.com/skills/fix-merge-conflicts): Fix merge conflicts is an open-source agent skill for developer tools.
- [Git merge](https://ai-powered.com/skills/git-merge): Git merge is an open-source agent skill for developer tools.
- [Make PR easy to review](https://ai-powered.com/skills/make-pr-easy-to-review): Make PR easy to review is an open-source agent skill for developer tools.
- [Repo cleanup loop](https://ai-powered.com/skills/repo-cleanup-loop): Repo cleanup loop is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/git-post-merge-cleanup
