Skip to content

Instantly share code, notes, and snippets.

@pingcheng
Created September 11, 2019 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pingcheng/136f404e86761491f7b813a5632b4720 to your computer and use it in GitHub Desktop.
Save pingcheng/136f404e86761491f7b813a5632b4720 to your computer and use it in GitHub Desktop.
Delete merged branches on local
#!/bin/sh
# get all merged branch
branches=$(git branch --merged master | grep -v '^[ *]*master$')
# define colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
LIGHT_GRAY='\e[90m'
NC='\033[0m'
# if no branches are need to clear, just exit
if [ -z "$branches" ]
then
echo "${GREEN}No merged branches to remove${NC}"
exit 0
fi
# delete each merged branch
for branch in $branches
do
echo "${LIGHT_GRAY}Deleting merged branch - ${YELLOW}${branch}${NC}"
git branch -d $branch
done
echo "${GREEN}Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment