git-branch-cleanup

Delete non-main local Git branches and pull latest changes.

Updated Mar 21, 2026
One-click install
npx skills add https://github.com/tatsushige-i/shared-claude-code --skill git-branch-cleanup-tatsushige-i
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: git-branch-cleanup
Source: https://github.com/tatsushige-i/shared-claude-code/tree/main/docs/ja-JP/skills/git-branch-cleanup
Command: npx skills add https://github.com/tatsushige-i/shared-claude-code --skill git-branch-cleanup-tatsushige-i

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Clean up local Git branches after PR creation or merge to keep the repository tidy and avoid confusion from stale branches.

Core Features & Use Cases

  • Switches to the main branch if not already on it.
  • Deletes all local branches except main in a single operation.
  • Pulls the latest changes from the remote after cleanup.
  • Use Case: After merging a PR, run this skill to ensure your local environment reflects the mainline and has no extra branches.

Quick Start

Run the single Bash command chain from the repository root to cleanup local branches.

Frequently Asked Questions about git-branch-cleanup

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I clean up local Git branches after a PR merge?

To clean up local Git branches after a PR merge, you switch to the main branch, delete all non-main local branches, and pull the latest remote changes in a single Bash command chain.

What is the best way to delete all local Git branches except main?

The best way to delete all local Git branches except main is using an automated Bash workflow that safeguards the main branch while removing other branches and pulling the latest mainline updates.

How does a Git branch cleanup script handle uncommitted changes?

A Git branch cleanup script handles uncommitted changes by running pre-checks before deleting branches, ensuring your local repository is tidy and preventing accidental data loss during the workflow.

Can I automate switching to main and pruning local branches in one step?

Yes, you can automate switching to main and pruning local branches in one step using a deterministic Bash command chain that deletes extra branches and pulls the latest remote changes.

Why should I prune local Git branches after creating a PR?

You should prune local Git branches after creating a PR to keep your repository tidy and avoid confusion from stale branches, ensuring your local environment accurately reflects the mainline codebase.