Working locally may lead to accumulating many git branches, but most of the time, we only want to keep the "main" or "master" branch. To achieve this, run the following command
If you are using "main" as the primary branch
git branch | grep -v "main" | xargs git branch -D
Or you are using "master" as the primary branch
git branch | grep -v "master" | xargs git branch -D
g
it branch
- List all available local branches.
(or) grep -v "main"
grep -v "master"
- Exclude the main or master branch from the list of output branches.
- runs xargs git branch -D
to all the branches inside the branch list. git branch -D