Skip to content

Instantly share code, notes, and snippets.

@alanplatt
Last active February 13, 2023 15:40
Show Gist options
  • Save alanplatt/1b78f0623fb5c3128700d7bc177840ca to your computer and use it in GitHub Desktop.
Save alanplatt/1b78f0623fb5c3128700d7bc177840ca to your computer and use it in GitHub Desktop.
Git function to delete all branches merged to default branch
_gbclean () {
default_branch=$( git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git checkout "${default_branch}" && git pull && \
for branch in $(git branch -l | grep -v -e "${default_branch}" ); do
git branch -d $branch
done
}
alias gbclean='_gbclean'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment