Files
wehub-resource-sync bb5c75ce05
Component Security Validation / Security Audit (push) Has been cancelled
Deploy to Cloudflare Pages / deploy (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:38:58 +08:00

1 line
6.1 KiB
JSON

{"content": "---\nallowed-tools: Bash(git branch:*), Bash(git checkout:*), Bash(git push:*), Bash(git merge:*), Bash(gh:*), Read, Grep\nargument-hint: [--dry-run] | [--force] | [--remote-only] | [--local-only]\ndescription: Use PROACTIVELY to clean up merged branches, stale remotes, and organize branch structure\n---\n\n# Git Branch Cleanup & Organization\n\nClean up merged branches and organize repository structure: $ARGUMENTS\n\n## Current Repository State\n\n- All branches: !`git branch -a`\n- Recent branches: !`git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short) - %(committerdate:relative)'`\n- Remote branches: !`git branch -r`\n- Merged branches: !`git branch --merged main 2>/dev/null || git branch --merged master 2>/dev/null || echo \"No main/master branch found\"`\n- Current branch: !`git branch --show-current`\n\n## Task\n\nPerform comprehensive branch cleanup and organization based on the repository state and provided arguments.\n\n## Cleanup Operations\n\n### 1. Identify Branches for Cleanup\n- **Merged branches**: Find local branches already merged into main/master\n- **Stale remote branches**: Identify remote-tracking branches that no longer exist\n- **Old branches**: Detect branches with no recent activity (>30 days)\n- **Feature branches**: Organize feature/* hotfix/* release/* branches\n\n### 2. Safety Checks Before Deletion\n- Verify branches are actually merged using `git merge-base`\n- Check if branches have unpushed commits\n- Confirm branches aren't the current working branch\n- Validate against protected branch patterns\n\n### 3. Branch Categories to Handle\n- **Safe to delete**: Merged feature branches, old hotfix branches\n- **Needs review**: Unmerged branches with old commits\n- **Keep**: Main branches (main, master, develop), active feature branches\n- **Archive**: Long-running branches that might need preservation\n\n### 4. Remote Branch Synchronization\n- Remove remote-tracking branches for deleted remotes\n- Prune remote references with `git remote prune origin`\n- Update branch tracking relationships\n- Clean up remote branch references\n\n## Command Modes\n\n### Default Mode (Interactive)\n1. Show branch analysis with recommendations\n2. Ask for confirmation before each deletion\n3. Provide summary of actions taken\n4. Offer to push deletions to remote\n\n### Dry Run Mode (`--dry-run`)\n1. Show what would be deleted without making changes\n2. Display branch analysis and recommendations\n3. Provide cleanup statistics\n4. Exit without modifying repository\n\n### Force Mode (`--force`)\n1. Delete merged branches without confirmation\n2. Clean up stale remotes automatically\n3. Provide summary of all actions taken\n4. Use with caution - no undo capability\n\n### Remote Only (`--remote-only`)\n1. Only clean up remote-tracking branches\n2. Synchronize with actual remote state\n3. Remove stale remote references\n4. Keep all local branches intact\n\n### Local Only (`--local-only`)\n1. Only clean up local branches\n2. Don't affect remote-tracking branches\n3. Keep remote synchronization intact\n4. Focus on local workspace organization\n\n## Safety Features\n\n### Pre-cleanup Validation\n- Ensure working directory is clean\n- Check for uncommitted changes\n- Verify current branch is safe (not target for deletion)\n- Create backup references if requested\n\n### Protected Branches\nNever delete branches matching these patterns:\n- `main`, `master`, `develop`, `staging`, `production`\n- `release/*` (unless explicitly confirmed)\n- Current working branch\n- Branches with unpushed commits (unless forced)\n\n### Recovery Information\n- Display git reflog references for deleted branches\n- Provide commands to recover accidentally deleted branches\n- Show SHA hashes for branch tips before deletion\n- Create recovery script if multiple branches deleted\n\n## Branch Organization Features\n\n### Naming Convention Enforcement\n- Suggest renaming branches to follow team conventions\n- Organize branches by type (feature/, bugfix/, hotfix/)\n- Identify branches that don't follow naming patterns\n- Provide batch renaming suggestions\n\n### Branch Tracking Setup\n- Set up proper upstream tracking for feature branches\n- Configure push/pull behavior for new branches\n- Identify branches missing upstream configuration\n- Fix broken tracking relationships\n\n## Output and Reporting\n\n### Cleanup Summary\n```\nBranch Cleanup Summary:\n✅ Deleted 3 merged feature branches\n✅ Removed 5 stale remote references\n✅ Cleaned up 2 old hotfix branches\n⚠️ Found 1 unmerged branch requiring attention\n📊 Repository now has 8 active branches (was 18)\n```\n\n### Recovery Instructions\n```\nBranch Recovery Commands:\ngit checkout -b feature/user-auth 1a2b3c4d # Recover feature/user-auth\ngit push origin feature/user-auth # Restore to remote\n```\n\n## Best Practices\n\n### Regular Maintenance Schedule\n- Run cleanup weekly for active repositories\n- Use `--dry-run` first to review changes\n- Coordinate with team before major cleanups\n- Document any non-standard branches to preserve\n\n### Team Coordination\n- Communicate branch deletion plans with team\n- Check if anyone has work-in-progress on old branches\n- Use GitHub/GitLab branch protection rules\n- Maintain shared documentation of branch policies\n\n### Branch Lifecycle Management\n- Delete feature branches immediately after merge\n- Keep release branches until next major release\n- Archive long-term experimental branches\n- Use tags to mark important branch states before deletion\n\n## Example Usage\n\n```bash\n# Safe interactive cleanup\n/branch-cleanup\n\n# See what would be cleaned without changes\n/branch-cleanup --dry-run\n\n# Clean only remote tracking branches\n/branch-cleanup --remote-only\n\n# Force cleanup of merged branches\n/branch-cleanup --force\n\n# Clean only local branches\n/branch-cleanup --local-only\n```\n\n## Integration with GitHub/GitLab\n\nIf GitHub CLI or GitLab CLI is available:\n- Check PR status before deleting branches\n- Verify branches are actually merged in web interface\n- Clean up both local and remote branches consistently\n- Update branch protection rules if needed"}