Search code examples
gitgit-branch

How to delete a whole folder/namespace (e.g. `bug/`) of branches?


I have many local branches under different folders eg. bug/the-branch or feat/the-branch.

How can i remove every branch under a certain name?


Solution

  • List all branches under the name:

    git for-each-ref --format="%(refname:short)" refs/heads/feat/
    

    and delete them one by one:

    git for-each-ref --format="%(refname:short)" refs/heads/feat/ |
        xargs -n1 git branch -D
    

    Please be advised you cannot remove the current branch so first checkout a different branch not under the top name.