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
-
`git branch -d
` deletes a branch. Does that answer your question? – Joachim Sauer Aug 17 '22 at 12:39 -
9Branches aren't in folders. If you mean that you have `br/anch`, `br/anch2`, `br/anch3`, etc., and want to remove all `br/*` branches: you have to do that one by one (well, technically you can generate the complete list and run one `git branch -d` with the list, but it's the same kind of thing anyway). These names resemble folders (and have the same limitations as folders) but aren't actually folders. – torek Aug 17 '22 at 12:41
-
2To add to what @torek said, the forward slash '/' in a branch name is just a character of the branch's name. It does not itself group branches together, that is purely up to your interpretation of the names. – Torge Rosendahl Aug 17 '22 at 13:00
-
1Take a look into this https://stackoverflow.com/questions/6127328/how-do-i-delete-all-git-branches-which-have-been-merged – Torge Rosendahl Aug 17 '22 at 13:14
-
`git branch -d
` might work, depending on your shell. – Biffen Aug 17 '22 at 13:15 -
git branch -d
deletes a branch. Does that answer your question? – In that way I must delete branches one by one, but I would like to remove all branches which in feature/* – Dmee Aug 17 '22 at 15:39
1 Answers
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.

- 482
- 6
- 17