0

A very similar question has already been asked here: Remove local branches no longer on remote

But answers given refer to branches merged into master. I want to remove all branches on my machine that do not have a reference on remote.

Example: I carry out some work on a feature branch feat-improvements, that gets pushed to remote, reviewed, merged to master, and deleted by the reviewer on remote. But I forgot to get rid of the branch locally by using the standard git branch -D feat-improvements, subsequently I've created a whole load of other other fix/feature branches I want to get rid of. now I want to get rid of now in one hit.

Community
  • 1
  • 1
mohammedkhan
  • 953
  • 6
  • 14
  • 1
    Possible duplicate of [How to prune local tracking branches that do not exist on remote anymore](http://stackoverflow.com/questions/13064613/how-to-prune-local-tracking-branches-that-do-not-exist-on-remote-anymore) – Yaroslav Admin Jan 18 '16 at 14:47

1 Answers1

-1

try something like this:

git branch -D `git branch | grep -E '(?!branch-that-will-not-be-deleted|another-branch-to-avoid).+'`

It uses one regex that ignore everything on the output of git branch (get all the branchs) that match the name branch-that-will-not-be-deleted e another-branch-to-avoid.

So the argument passed to git branch -D will be all the branchs except the explicted in the regex.