Add this to your .gitconfig file.
[alias]
cleanup = !git branch --merged | grep -v \"\\*\" | grep -v \"\\+\" | grep -v main | grep -v master | grep -v dev | xargs -r -p git branch -DRun git cleanup, after the prompt, enter y to confirm, and it will automatically delete all the merged branches in your repository.
This will not delete the following branches:
mainmasterdev- Current
HEAD - Branches checked out in a worktree