List remote branches already merged to main
git fetch origin > /dev/null; git checkout origin/main; for branch in $( git branch -a --merged | grep remotes/origin | grep -v main | grep -v ' no branch' | sed -e ' s/\s*remotes\///' ) ; do echo " ${branch: 7} " ; done ; git checkout main
Delete remote branches already merged to main
git fetch origin > /dev/null; git checkout origin/main; for branch in $( git branch -a --merged | grep remotes/origin | grep -v main | grep -v ' no branch' | sed -e ' s/\s*remotes\///' ) ; do git push origin :${branch: 7} " ; done; git checkout main
List local branches already merged to main
git fetch origin > /dev/null; git checkout origin/main; for branch in $( git branch --merged | grep -v main | grep -v ' no branch' ) ; do echo " $branch " ; done ; git checkout main
Delete local branches already merged to main
git fetch origin > /dev/null; git checkout origin/main; for branch in $( git branch --merged | grep -v main | grep -v ' no branch' ) ; do git branch -D $branch ; done ; git checkout main