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! :)
@sshleifer I think it should work just fine, if you keep your local "main" branch (e.g.
master
) up to date with the upstream repo, e.g. you can usegit remove add upstream [repourl]
and thengit pull upstream master
to refresh you local branch. I would also recommend to keep your fork up to date. Then the script would use that to check wether branches are merged. I have to admit I don't use this script anymore since we often sqaush-merge now 😅