Git Branch Cleanup & Organization

Command

by davila7 · Added 5mo ago

Claude

Install

npx claude-code-templates@latest --command=cli-tool/components/commands/git-workflow --yes

Add to Claude

claude mcp add git-branch-cleanup-organization

About


allowed-tools: Bash(git branch:), Bash(git checkout:), Bash(git push:), Bash(git merge:), Bash(gh:*), Read, Grep argument-hint: [--dry-run] | [--force] | [--remote-only] | [--local-only] description: Use PROACTIVELY to clean up merged branches, stale remotes, and organize branch structure

Git Branch Cleanup & Organization

Clean up merged branches and organize repository structure: $ARGUMENTS

Current Repository State

  • All branches: !git branch -a
  • Recent branches: !git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short) - %(committerdate:relative)'
  • Remote branches: !git branch -r
  • Merged branches: !git branch --merged main 2>/dev/null || git branch --merged master 2>/dev/null || echo "No main/master branch found"
  • Current branch: !git branch --show-current

Task

Perform comprehensive branch cleanup and organization based on the repository state and provided arguments.

Cleanup Operations

1. Identify Branches for Cleanup

  • Merged branches: Find local branches already merged into main/master
  • Stale remote branches: Identify remote-tracking branches that no longer exist
  • Old branches: Detect branches with no recent activity (>30 days)
  • Feature branches: Organize feature/* hotfix/* release/* branches

2. Safety Checks Before Deletion

  • Verify branches are actually merged using git merge-base
  • Check if branches have unpushed commits
  • Confirm branches aren't the current working branch
  • Validate against protected branch patterns

3. Branch Categories to Handle

  • Safe to delete: Merged feature branches, old hotfix branches
  • Needs review: Unmerged branches with old commits
  • Keep: Main branches (main, master, develop), active feature branches
  • Archive: Long-running branches that might need preservation

4. Remote Branch Synchronization

  • Remove remote-tracking branches for deleted remotes
  • Prune remote references with `git remote prune origi

Tags

CodeAnalysisaitmplclaude-code-templates

From Our Store

View all →
Claude Code

Claude Code Power User Kit

$39+

Advanced Claude Code skills and configurations

OpenClaw

OpenClaw Business Starter Kit

$59+

Set Up Your AI Assistant in 60 Minutes