I have been deleting my local branches with a command I found on the web some time ago, but when I analyse it, I'm not sure what grep -v "\*" is doing in the command line, I remove it and is still doing the same (or at least I think so). I don't find any information about it on the web. Also, I found a variant that is just grep -v "*". It doesn't make sense to search for a branch with the name "*" because is not possible to call it like that (at least on sourcetree)
Here is the command I have been using.
git branch --merged | grep -v "\*" | grep -v master | grep -v develop | xargs -n 1 git branch -d
Can someone tell me if it is important or if I just can remove it from the command line?
It filters the input leaving all lines that do not contain an asterisk.
From man grep:
-v, --invert-match Invert the sense of matching, to select non-matching lines. (-v is specified by POSIX.)
\* is a pattern that matches asterisks. Due to the -v flag, these lines will be removed from the output.
In this context, the grep command will filter the output of git branch --merged.
The latter outputs a list of branches, out of which the current branch is marked with an asterisk. grep -v "\*" simply removes the current branch from the output.
Finally, your whole command will delete all merged branches, except master, develop and the current branch.
If you leave out the first grep, the command will attempt to remove the currently checked out branch, which will result in an error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With