Can I delete all the local branches except the current one?

后端 未结 14 2315
广开言路
广开言路 2020-12-12 13:07

I want to delete all branches that get listed in the output of ...

$ git branch

... but keeping current branch, in one step. Is th

相关标签:
14条回答
  • 2020-12-12 13:39

    For Windows, in Powershell use:

    git branch | %{ $_.Trim() } | ?{ $_ -ne 'master' } | %{ git branch -D $_ }
    
    0 讨论(0)
  • 2020-12-12 13:41

    Delete all branches except a specific branch:

    git branch | grep -v "branch name" | xargs git branch -D
    

    Delete all local branches except develop and master

    git branch | grep -v "develop" | grep -v "master" | xargs git branch -D
    
    0 讨论(0)
提交回复
热议问题