Mailo Mailo - 3 months ago 8
Git Question

Remove local branches no longer on remote

Is there a simple way to delete all local branches which do not have a remote equivalent?

Example:

Branches (local and remote)


  • master

  • origin/master

  • origin/bug-fix-a

  • origin/bug-fix-b

  • origin/bug-fix-c



Locally, I only have a master branch. Now I need to work on bug-fix-a, so I check it out, work on it, and push changes to the remote. Next I do the same with bug-fix-b.

Branches (local and remote)


  • master

  • bug-fix-a

  • bug-fix-b

  • origin/master

  • origin/bug-fix-a

  • origin/bug-fix-b

  • origin/bug-fix-c



Now I have local branches master, bug-fix-a, bug-fix-b. The Master branch maintainer will merge my changes into master and delete all branches he has already merged.

So the current state is now:

Branches (local and remote)


  • master

  • bug-fix-a

  • bug-fix-b

  • origin/master

  • origin/bug-fix-c



Now I would like to call some command to delete branches (in this case bug-fix-a, bug-fix-b), which are no longer represented in the remote repository.

It would be something like the existing command
git remote prune origin
, but more like
git local prune origin
.

Answer

Seems solution is here – http://stackoverflow.com/a/1072178/133986

In short, git remote prune does the magic