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

后端 未结 14 2462
广开言路
广开言路 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:30

    Assuming git branch shows the current branch prefixed with *; Using Powershell the following one liner will delete all branches that don't start with *.

    git branch | ? { $_ -lt "*" } | % { git branch -D $_.Trim() }

    ? = Where-Object

    % = Foreach-Object

提交回复
热议问题