Created
May 14, 2013 15:54
-
-
Save ctavan/5577065 to your computer and use it in GitHub Desktop.
Remove merged git branches
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/sh | |
REMOTE=${1:-origin} | |
BRANCH=$(git symbolic-ref -q HEAD) || BRANCH='(unknown branch)' | |
BRANCH=${BRANCH##refs/heads/} | |
REMOTE_MERGED=$( git branch -r --merged | | |
grep -v master | | |
grep -v "$BRANCH" | | |
sed -n "s,$REMOTE/,,p" | |
) | |
if [ "x$REMOTE_MERGED" != "x" ] | |
then | |
echo "Delete these merged remote branches?" | |
echo $REMOTE_MERGED | |
read -p "[y/n] " DELETE_REMOTE | |
if [ "$DELETE_REMOTE" == "y" ] | |
then | |
echo $REMOTE_MERGED | xargs -L3 git push --delete "$REMOTE" | |
fi | |
fi | |
LOCAL_MERGED=$( git branch --merged | | |
grep -Ev '^\*|master' | |
) | |
if [ "x$LOCAL_MERGED" != "x" ] | |
then | |
echo "Delete these merged local branches?" | |
echo $LOCAL_MERGED | |
read -p "[y/n] " DELETE_LOCAL | |
if [ "$DELETE_LOCAL" == "y" ] | |
then | |
echo $LOCAL_MERGED | xargs -L10 git branch -d | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment