如何在Bitbucket中单次删除多个分支?支持命令行或手动操作吗?
How to Delete Multiple Branches in Bitbucket at Once
Absolutely! You can delete multiple Bitbucket branches in one go—either via the command line (using Git) or manually through the Bitbucket web interface. Let’s walk through both methods step by step:
Command Line Method (Git)
This is perfect if you prefer terminal workflows or need to automate branch cleanup. Just ensure your local repo is linked to your Bitbucket remote first:
- First, update your local list of remote branches to match what’s on Bitbucket:
git fetch --prune - To delete specific individual branches, list them all in one
git pushcommand:git push origin --delete feature/login-flow bugfix/payment-error docs/update-api-ref - For bulk deletion using a pattern (e.g., delete all branches starting with
feature/), use a shell command to filter and delete:
Quick breakdown of the pattern command:git push origin --delete $(git branch -r | grep 'origin/feature/' | sed 's/origin\///')git branch -rlists all remote branchesgrep 'origin/feature/'filters to only branches under thefeature/prefixsed 's/origin\///'removes theorigin/prefix from branch names so Git recognizes them correctly- Pro tip: Double-check the filtered list before running the full command by testing just the part inside the parentheses first!
Manual Web Interface Method
If you prefer a visual approach, Bitbucket’s web UI supports bulk branch deletion directly:
- Navigate to your Bitbucket repository and click Branches in the left sidebar
- Use the search bar or filter options (like switching from "Active" to "All branches") to find the branches you want to delete
- Check the checkbox next to each branch you want to remove (you can select as many as needed)
- Once selected, click the Delete button at the top or bottom of the branch list, then confirm the deletion when prompted
Important Notes
- Make sure you have the necessary permissions to delete branches in the repository (usually admin or write access)
- Always double-check that the branches you’re deleting are no longer needed—either merged into the main branch or obsolete. Avoid deleting critical branches like
mainormasterby accident!
内容的提问来源于stack exchange,提问作者Anupam Mishra




