Runar Ovesen Hjerpbakk

Software Philosopher

Remove local branches not present on GitHub

I mostly use GitHub’s desktop client while working with GitHub repositories. This means that I get less exposure to the git CLI (command line interface) commands than perhaps is healthy.

But sometimes even I need to go old school.

When you’re merging a pull request and push that very useful button Delete branch, your branch will be deleted on GitHub but remain locally.

To fix this and delete all branches which exist locally but not on GitHub, you can run:

git remote prune origin

origin, in this case, will be your GitHub repo.

The full command is this and works on any remote:

git remote prune <name>

prune deletes all stale remote-tracking branches under <name>. These stale branches have already been removed from the remote repository referenced by <name>, but are still locally available in “remotes/<name>”.

The --dry-run option will report what branches will be pruned, but not actually prune them.