Switch to the Branch You Want to Clean Up
Before you start cleaning up merged branches, ensure you’re on the branch from which you want to remove the merged branches. Typically, this is the main development branch, such as master or main.
git checkout master
How to Delete all Git Branches which have been Merged?
To delete Git branches that have been merged into the current branch, you can use a combination of git branch and git branch -d commands along with some scripting. Below is a step-by-step guide:
Table of Content
- Switch to the Branch You Want to Clean Up
- List Merged Branches
- Delete Merged Branches
- Force Delete (if necessary)
- Confirmation
- Additional Tips