Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #/ Usage: clean-merged-branches
- #/ Delete locally merged branches
- set -e
- # show usage maybe
- [ "$1" = "--help" ] && {
- grep '^#/' <"$0"| cut -c4-
- exit 0
- }
- # fetch and prune remote branches
- git fetch origin --prune
- # Delete merged local branches
- git branch --merged | grep -v '*' | grep -v master | xargs git br -d
- # grab list of merged branches
- branches=$(
- git branch -r --merged |
- sed 's@origin/@@'
- )
- # bail out with no branches
- [ -z "$branches" ] && {
- echo "no merged branches detected" 1>&2
- exit 0
- }
- # delete the branches or just show what would be done without -f
- echo "Merged branches on origin: " 1>&2
- echo "$branches"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement