Current Answer
I didn't read the comments. the best is the answer at stackoverflow.com/a/13437928/7976758:
$ git push --prune origin Previous Answer:
Stumbled onto this question, here's how I did it, it's not exactly automated but this should be a start.
Step 1: Delete local branches
Step 1: Delete local branches
- Get list of local branches
$ git --no-pager branch --sort=-committerdate > branches_to_delete.txt Delete the rows not to be deleted in file
branches_to_delete.txtdelete the branches at local
$ cat branches_to_delete.txt | xargs git branch -D Step 2: Delete remote branches
Step 2: Delete remote branches
- Get list of remote branches
$ git remote prune origin # delete all the local refs to already-deleted remote branches $ git --no-pager branch -r --sort=-committerdate > branches_to_delete.txt delete branches not to be deleted in file
branches_to_delete.txtreplace all "origin/" with "" (vim, emacs, vscode, sed, etc.) in file
delete the branches at remote:
$ cat branches_to_delete.txt | xargs git push origin --delete