| name | git-prune-branches-remote |
| description | Clean up remote git branches that have been merged into origin/main. Use when: (1) User says 'prune remote branches' or 'clean remote branches', (2) User wants to delete only remote merged branches without touching local. |
Git Prune Branches (Remote)
Check and prune remote branches that have been merged:
- Fetch the latest remote information using
git fetch --prune
- Get the list of all remote branches using
git branch -r
- For each remote branch, check if it has been merged into the remote main branch using
git branch -r --merged origin/main (or appropriate main branch)
- Exclude protected branches (main, master, develop, etc.)
- Create a list of remote branches that are safe to delete
- Present the deletion list to the user clearly
- Ask for confirmation: "The following remote branches will be deleted. Proceed? (yes/no)"
- If user confirms with "yes" or similar affirmative response, delete the remote branches using
git push origin --delete <branch-name> for each branch
- Report the results
Important: Never delete:
- Protected branches: main, master, develop, development, staging, production
- Branches that are not fully merged (unless explicitly requested)
Note: This operation affects the remote repository and cannot be easily undone. Ensure user confirmation before proceeding.