Skip to main content
added 109 characters in body
Source Link
Viet Than
  • 318
  • 3
  • 12

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

  1. Get list of local branches
$ git --no-pager branch --sort=-committerdate > branches_to_delete.txt 
  1. Delete the rows not to be deleted in file branches_to_delete.txt

  2. delete the branches at local

$ cat branches_to_delete.txt | xargs git branch -D 

Step 2: Delete remote branches

Step 2: Delete remote branches

  1. 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 
  1. delete branches not to be deleted in file branches_to_delete.txt

  2. replace all "origin/" with "" (vim, emacs, vscode, sed, etc.) in file

  3. delete the branches at remote:

$ cat branches_to_delete.txt | xargs git push origin --delete 

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

  1. Get list of local branches
$ git --no-pager branch --sort=-committerdate > branches_to_delete.txt 
  1. Delete the rows not to be deleted in file branches_to_delete.txt

  2. delete the branches at local

$ cat branches_to_delete.txt | xargs git branch -D 

Step 2: Delete remote branches

  1. 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 
  1. delete branches not to be deleted in file branches_to_delete.txt

  2. replace all "origin/" with "" (vim, emacs, vscode, sed, etc.) in file

  3. delete the branches at remote:

$ cat branches_to_delete.txt | xargs git push origin --delete 

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

  1. Get list of local branches
$ git --no-pager branch --sort=-committerdate > branches_to_delete.txt 
  1. Delete the rows not to be deleted in file branches_to_delete.txt

  2. delete the branches at local

$ cat branches_to_delete.txt | xargs git branch -D 

Step 2: Delete remote branches

  1. 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 
  1. delete branches not to be deleted in file branches_to_delete.txt

  2. replace all "origin/" with "" (vim, emacs, vscode, sed, etc.) in file

  3. delete the branches at remote:

$ cat branches_to_delete.txt | xargs git push origin --delete 
Source Link
Viet Than
  • 318
  • 3
  • 12

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

  1. Get list of local branches
$ git --no-pager branch --sort=-committerdate > branches_to_delete.txt 
  1. Delete the rows not to be deleted in file branches_to_delete.txt

  2. delete the branches at local

$ cat branches_to_delete.txt | xargs git branch -D 

Step 2: Delete remote branches

  1. 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 
  1. delete branches not to be deleted in file branches_to_delete.txt

  2. replace all "origin/" with "" (vim, emacs, vscode, sed, etc.) in file

  3. delete the branches at remote:

$ cat branches_to_delete.txt | xargs git push origin --delete