Skip to content

Instantly share code, notes, and snippets.

@marcpeabody
Created March 9, 2017 15:53
Show Gist options
  • Save marcpeabody/60d621157385e1ef98fca7ba67414ed5 to your computer and use it in GitHub Desktop.
Save marcpeabody/60d621157385e1ef98fca7ba67414ed5 to your computer and use it in GitHub Desktop.
git branch deletion
function git_bd { # git local branch deletion
# deletes any local feature branches no longer needed
# branches without a remote are kept
# branches with unpushed changes are kept
git checkout master
for bra in `git branch | awk '/([0-9].*)/ {print $1}'`
do
set -A o `git branch -r | grep $bra`
if [ "$o" != "" ]
then
set -A diff "`git cherry -v $o $bra`"
if [ "$diff" != "" ]
then
echo $bra has unpushed changes. not deleting
else
git branch -D $bra
fi
else
echo $bra did not have an origin of the same name
fi
done
git branch
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment