If you have too many Git branches, bookmark and like this page.
Note: You'll see
"(^*|master|main|develop|release)"
a lot in the below scripts. This is a regular expression that excludes those long-lived branches so those won't be considered.
To list all local branches that have been merged into the current branch:
git branch --merged | egrep -v "(^*|master|main|develop|release)"
To list all branches that have been merged into the current branch:
git branch -r --merged | egrep -v "(^*|master|main|develop|release)"
To PURGE all local branches that have been merged into the current branch:
git branch --merged | egrep -v "(^*|master|main|develop|release)" | xargs git branch -d
STOP!
Be very, VERY certain you know what you are doing. This following command modifies the shared repo and unless there is a perfect clone, it has the potential to remove branches that people don’t have a reference to.
To PURGE all REMOTE branches that have been merged into the current branch:
git branch --merged | egrep -v "(^*|master|main|develop|release)" | xargs git push --delete origin
Top comments (1)
cool, I give thia a try