Last active
February 16, 2021 15:39
-
-
Save kerasai/fa1fb5d3008044f0668512903b9583a8 to your computer and use it in GitHub Desktop.
Delete merged git branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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