Goal Delete all branches except for several exceptions. In my case: development, main
I found this command but it only applies to main.
git branch | grep -v "main" | xargs git branch -D
I thought you could do it like this:
git branch | grep -v "main|development" | xargs git branch -D
But that doesn't work.
CodePudding user response:
Basic regular expressions require you to escape the |
, which is otherwise treated as a literal character, to indicate alternation.
git branch | grep -v "main\|development"
If your version of grep
supports it, you can use extended regular expression, in which |
is the alternation operator.
git branch | grep -Ev "main|development"
CodePudding user response:
Escape the Pipe in your pattern \|
. Like that:
git branch | grep -v "branchName1\|branchName2\|branchName3" | xargs git branch -D