Skip to content

Instantly share code, notes, and snippets.

@zacdaryl
Last active March 22, 2019 07:58
Show Gist options
  • Save zacdaryl/2daef2c7bac3b01d9423c724b4b9f1fe to your computer and use it in GitHub Desktop.
Save zacdaryl/2daef2c7bac3b01d9423c724b4b9f1fe to your computer and use it in GitHub Desktop.
Delete branches which have merged
#!/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