Last active
March 22, 2019 07:58
-
-
Save zacdaryl/2daef2c7bac3b01d9423c724b4b9f1fe to your computer and use it in GitHub Desktop.
Delete branches which have merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Delete remote branches which have merged to master | |
| if [[ $1 == '-r' ]]; then | |
| git branch --all --merged remotes/origin/master | \ | |
| grep --invert-match master | \ | |
| grep --invert-match HEAD | \ | |
| grep "remotes/origin/" | \ | |
| cut -d "/" -f 3- | \ | |
| xargs -n 1 git push --delete origin | |
| exit 0 | |
| fi | |
| # Delete local branches which have merged to master | |
| git branch -d `git branch --merged | grep --invert-match master` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment