I have some folders like feature and fix and etc. I want to delete localy all infromation about this branch, because they were already merged and I don't want to see them when call "git branch" or "git branch -r", so the quesation in the titile
CodePudding user response:
TL;DR
This should do the trick.
git branch -d $(git branch | grep "^ fix/")
Explanation
The idea of this is to provide git branch -d
(delete branch if merged) with a list of all interesting branches, i.e. all branches that start with "fix/"
.
This list is generated by git branch | grep "^ fix/"
.
This command is made up of two parts:
git branch
: Lists all local branches (on seperate lines).grep " fix/"
: Only passes lines that begin with" fix/"
.
Executing a command cmd2
with multiple lines of output through cmd1 $(cmd2)
causes the preceding command cmd1
to be executed once for each line. Therefore, all matching branches are deleted.
You can of course replace "fix/" with "feature/" or anything else.
Note: The two spaces at the start of the line are very important to match. The currently checked out branch is listed beginning with *
. The asterisk (*
) tries to match all files in the folder, leading to git trying to delete all branches named like files in the current directory.