Home / Market / branch cleanup

branch cleanup

branch-cleanup

claude-command★ 348000 dlgithubMITInstall in CosmosUpstream Source

Documentation & Preview

--- 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

Task

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

Cleanup Operations

1. Identify Branches for Cleanup

2. Safety Checks Before Deletion

3. Branch Categories to Handle

4. Remote Branch Synchronization

Command Modes

Default Mode (Interactive)

  1. Show branch analysis with recommendations
  2. Ask for confirmation before each deletion
  3. Provide summary of actions taken
  4. Offer to push deletions to remote

Dry Run Mode (--dry-run)

  1. Show what would be deleted without making changes
  2. Display branch analysis and recommendations
  3. Provide cleanup statistics
  4. Exit without modifying repository

Force Mode (--force)

  1. Delete merged branches without confirmation
  2. Clean up stale remotes automatically
  3. Provide summary of all actions taken
  4. Use with caution - no undo capability

Remote Only (--remote-only)

  1. Only clean up remote-tracking branches
  2. Synchronize with actual remote state
  3. Remove stale remote references
  4. Keep all local branches intact

Local Only (--local-only)

  1. Only clean up local branches
  2. Don't affect remote-tracking branches
  3. Keep remote synchronization intact
  4. Focus on local workspace organization

Safety Features

Pre-cleanup Validation

Protected Branches

Never delete branches matching these patterns:

Recovery Information

Branch Organization Features

Naming Convention Enforcement

Branch Tracking Setup

Output and Reporting

Cleanup Summary

Branch Cleanup Summary:
✅ Deleted 3 merged feature branches
✅ Removed 5 stale remote references
✅ Cleaned up 2 old hotfix branches
⚠️  Found 1 unmerged branch requiring attention
📊 Repository now has 8 active branches (was 18)

Recovery Instructions

Branch Recovery Commands:
git checkout -b feature/user-auth 1a2b3c4d  # Recover feature/user-auth
git push origin feature/user-auth            # Restore to remote

Best Practices

Regular Maintenance Schedule

Team Coordination

Branch Lifecycle Management

Example Usage

# Safe interactive cleanup
/branch-cleanup

# See what would be cleaned without changes
/branch-cleanup --dry-run

# Clean only remote tracking branches
/branch-cleanup --remote-only

# Force cleanup of merged branches
/branch-cleanup --force

# Clean only local branches
/branch-cleanup --local-only

Integration with GitHub/GitLab

If GitHub CLI or GitLab CLI is available: