Skip to content

Instantly share code, notes, and snippets.

@kerasai
Last active February 16, 2021 15:39
Show Gist options
  • Save kerasai/fa1fb5d3008044f0668512903b9583a8 to your computer and use it in GitHub Desktop.
Save kerasai/fa1fb5d3008044f0668512903b9583a8 to your computer and use it in GitHub Desktop.
Delete merged git branches
# Delete local branches.
git branch --merged main | grep -v "\* main" | xargs -n 1 git branch -d
# Delete local branches (seems to remove only some).
git remote prune origin
# Delete remote branches (dry run).
git branch -r --merged origin/main | grep -v 'origin/main' | sed -E 's/(origin\/)//'
# Delete remote branches (for real).
git branch -r --merged origin/main | grep -v 'origin/main' | sed -E 's/(origin\/)//' | xargs -n 1 -I % git push origin :%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment