Skip to content

Instantly share code, notes, and snippets.

@clauswitt
Created February 19, 2012 23:15
Show Gist options
  • Select an option

  • Save clauswitt/1866409 to your computer and use it in GitHub Desktop.

Select an option

Save clauswitt/1866409 to your computer and use it in GitHub Desktop.
Remove local branches (that are already merged to master)
#!/bin/bash
TMPFILE=".tmpGitLocals"
git branch --merged > $TMPFILE
COMMIT=$1
if [[ $COMMIT == "commit" ]]; then
echo "deleting git branches"
else
echo "dry run - call with commit to delete branches"
fi
function illegalBranch() {
if [[ "$1" == "master" ]]; then
echo 1
exit
fi
if [[ "$1" == "live" ]]; then
echo 1
exit
fi
if [[ "$1" == "* master" ]]; then
echo 1
exit
fi
echo 0
}
while read line; do
RESULT=`illegalBranch "$line"`
if [ $RESULT -eq 0 ]; then
if [[ $COMMIT == "commit" ]]; then
echo "running: git branch -d $line"
git branch -d $line
else
echo "git branch -d $line"
fi
fi
done<$TMPFILE
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment