Created
June 12, 2014 00:18
-
-
Save jonmoter/ea1b067c1db880a8e275 to your computer and use it in GitHub Desktop.
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 | |
shopt -s expand_aliases | |
function prompt_to_continue() | |
{ | |
read -p "Continue (y/n)? " | |
if [ "$REPLY" != "y" ]; then | |
exit 0 | |
fi | |
} | |
alias filter_branches="sed 's/^[ \*]*//g' | grep -Ev '^(master|release|production|staging|demo|heroku|HEAD)'" | |
base_branch="master" | |
git checkout $base_branch | |
# Update our list of remotes | |
git fetch || exit -1 | |
git remote prune origin || exit -1 | |
# Remove local fully merged branches | |
merged_branches=$(git branch --merged $base_branch | filter_branches) | |
if [ "$merged_branches" = "" ]; then | |
echo 'No local branches need deletion' | |
else | |
echo '' | |
echo "The following LOCAL branches are fully merged and will be removed" | |
for branch in $merged_branches ; do | |
echo " $branch" | |
done | |
echo '' | |
prompt_to_continue | |
for branch in $merged_branches ; do | |
git branch -d $branch || exit -1 | |
done | |
fi | |
# Show remote fully merged branches | |
merged_branches=$(git branch -r --merged $base_branch | sed 's/ *origin\///' | filter_branches) | |
if [ "$merged_branches" = "" ]; then | |
echo 'No remote branches need deletion' | |
else | |
echo '' | |
echo "The following remote branches are fully merged and will be removed:" | |
for branch in $merged_branches ; do | |
echo " $branch" | |
done | |
echo '' | |
prompt_to_continue || exit -1 | |
# Remove remote fully merged branches | |
for branch in $merged_branches ; do | |
git push origin :$branch || exit -1 | |
done | |
echo "Obsolete branches are removed" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment