This is a handy script to delete any leftover and merged git branches. It will detect branches merged into development and delete those, except branches named master or staging. These branch names can be configured by editing the script.
To install simply run:
curl -L https://git.io/vVHF6 | bash
Or manually put this script into ~/bin
and run chmod +x ~/bin/git-deletebranches.sh
.
If you run it the output will look like this:
~/my-git-repo> git-deletebranches.sh
Branches merged into development:
some-merged-feature-branch another-merged-feature-branch
Delete these branches (y/n)? y
Deleted branch some-merged-feature-branch (was 281d690).
Deleted branch another-merged-feature-branch (was 0b67c29).
You can also supply a branch name as a first argument, if your target branch is not named development
like this:
~/my-git-repo> git-deletebranches.sh master
Branches merged into master:
[...]
Enjoy! :)
This script already saved me today. I had pushed a feature branch to the remote repository, had the merge-request accepted and ran
git-deletebranches.sh
as I always do after my MRs got merged. However, one of the merged branches was not listed. At first I thought I had encountered a bug ingit-deletebranches.sh
but then it became clear: I had forgotten to push one commit in this branch toorigin
, so the branch was not fully merged. I ran:And when this branch got merged in the remote I did:
Yey, everything in check again.