I’m a big fan of keeping everything clean and tidy when it comes to development – things can quickly get out of control when redundant code is left lying around, or in this case when redundant branches and their references are left festering in your git repositories.

There are a few options for cleaning up your git repository and getting rid of old and invalid branches and their references.

Remote rm

What does this do? Remove the remote named . All remote tracking branches and configuration settings for the remote are removed.

The first thing to do with remote branches that are not longer required is to simply remove them – this should also cleanup the references however that’s not always the case in my experience. Replace ‘BRANCH’ in the below snippet with the name of the branch you want to remove.


What does this do? Deletes all stale tracking branches under . These stale branches have already been removed from the remote repository referenced by , but are still locally available in “remotes/”.

With –dry-run option, report what branches will be pruned, but do no actually prune them.


Remove local branches which have been removed from remote

Doing a simple ‘fetch’ will clean up any local branches which have been deleted from remote

If you’re using git 1.8.5+ then you can do this automatically setting the following in your config:

Leave a Reply