Created
March 30, 2016 16:55
-
-
Save ryanshoover/ce2645a9ebef9b3d2f56eb40318e8a10 to your computer and use it in GitHub Desktop.
Clean out dead branches from local and remote repos
This file contains 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 | |
## Typical usage | |
# gitclean | |
# gitclean remote | |
say() { echo "$0: $*" >&2; } | |
die() { say "$*"; exit 111; } | |
try() { "$@" || die "cannot $*"; } | |
# Clean GIT repo of all merged branches | |
git checkout staging; | |
git pull origin staging; | |
if [ "$1" == "remote" ] | |
then | |
echo "Cleaning " $1 | |
git branch --remote --list 'dev1/MAR\-*' --merged | xargs git branch -rd | |
git branch --remote --list 'dev2/MAR\-*' --merged | xargs git branch -rd | |
git branch --remote --list 'dev3/MAR\-*' --merged | xargs git branch -rd | |
elif [ "$1" == "github" ] | |
then | |
echo "Cleaning " $1 | |
git branch --remote --list 'origin/MAR-*' --merged | sed "s/origin\/MAR/:MAR/" | xargs git push origin | |
else | |
echo "Cleaning local" | |
git branch --list 'MAR\-*' --merged | xargs -J % git branch -d % | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment