Skip to content

Instantly share code, notes, and snippets.

@colbyfayock
Created April 29, 2019 23:45
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save colbyfayock/20982cd88760c2abc3e6c7bdc3a85dda to your computer and use it in GitHub Desktop.
Remove local branches that merged into the specified branch
# Example Usage: gpb develop
# Removes any branches that were already merged into develop
gpb() {
BRANCH=$1
BRANCHES_TO_CLEAN=$(git branch --merged=$BRANCH | grep -v $BRANCH)
echo "Branches that have been merged to develop:"
echo $BRANCHES_TO_CLEAN
read -q "REPLY?Remove branches? (y/n)"
echo ""
if [ "$REPLY" != "y" ]; then
echo "Response was not \"y\", aborting..."
return
fi
echo "Removing branches from local"
for i in `echo $BRANCHES_TO_CLEAN`; do
git branch -D $i
done
echo "Done."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment