Created
June 11, 2013 14:32
-
-
Save bbelyeu/5757303 to your computer and use it in GitHub Desktop.
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 | |
# @link https://coderwall.com/p/fkk2lw | |
if [ "$1" == "" ]; then | |
TRUNK="integration" | |
else | |
TRUNK=$1 | |
fi | |
if [ "$2" == "" ]; then | |
REMOTE_PREFIX="bb/" | |
else | |
REMOTE_PREFIX=$2 | |
fi | |
if git checkout $TRUNK > /dev/null 2>&1; then | |
echo "Successfully checked out $TRUNK !" | |
else | |
echo "Cannot checkout $TRUNK - check branch name and try again." | |
exit 1 | |
fi | |
# Update our list of remotes | |
echo "Updating remotes and pruning origin..." | |
git remote update > /dev/null 2>&1 | |
git remote prune origin > /dev/null 2>&1 | |
# Remove local fully merged branches | |
echo "Cleaning up local branches:" | |
if git branch --merged $TRUNK | grep -v $TRUNK | grep -v 'master'; then | |
read -p "Delete local branches (y/n)? " | |
if [ "$REPLY" == "y" ] | |
then | |
git branch --merged $TRUNK | grep -v $TRUNK | grep -v 'master' | xargs git branch -d | |
fi | |
else | |
echo "No local branches to clean up!" | |
fi | |
# Show remote fully merged branches | |
if git branch -r --merged $TRUNK | grep $REMOTE_PREFIX | sed 's/ *origin\///' | grep -v $TRUNK | grep -v 'master' > /dev/null 2>&1; then | |
echo "The following remote branches are fully merged and will be removed:" | |
git branch -r --merged $TRUNK | grep $REMOTE_PREFIX | sed 's/ *origin\///' | grep -v $TRUNK | grep -v 'master' | |
read -p "Continue (y/n)? " | |
if [ "$REPLY" == "y" ] | |
then | |
# Remove remote fully merged branches | |
git branch -r --merged $TRUNK | grep $REMOTE_PREFIX | sed 's/ *origin\///' | grep -v $TRUNK \ | |
| grep -v 'master' | xargs -I% git push origin :% | |
echo "Done!" | |
fi | |
else | |
echo "No remote branches to clean up!" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment