Skip to content

Instantly share code, notes, and snippets.

@julianburr
Created March 23, 2021 12:08
Show Gist options
  • Save julianburr/4ce05db39c58b1d1e4fbeb3c0255db0f to your computer and use it in GitHub Desktop.
Save julianburr/4ce05db39c58b1d1e4fbeb3c0255db0f to your computer and use it in GitHub Desktop.
Git - delete merged branches locally and remote
# https://stackoverflow.com/questions/6127328/how-can-i-delete-all-git-branches-which-have-been-merged
# Delete local branches that have been merged i.e. into "main"
git branch --merged main | grep -v "(^\*|main)" | xargs git branch -d
# Delete remote branches that have been merged i.e. into "main
git branch -r --merged main | grep -v "(^\*|main)" | sed 's/origin\///' | xargs -n 1 git push --delete origin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment