Delete all local branches except the ones you're working on
Most of us accumulate an endless list of local branches in the repositories we're working on.
Let me share with you a fast and easy way of removing all of the remaining local branches you're not or completed working on but forgot to delete from the repository.
Just execute the following command:
git branch -d $(git branch -l | grep -Ev "master|[EXCLUDED_BRANCHES])
Where the [EXCLUDED_BRANCHES] is a list of the branches you want to preserve in your local repository.
-d flag means that you want to delete only the branches that are eligible for deletion.
If you want to force delete them, use the
-D flag instead.