How to prune stale references to remote git branches
I can sling git about a fair amount, but for some reason I’ve never learned how to remove stale references to remote branches that have been deleted from the server.
Perhaps embarrassingly, my current workflow for this is finding the remote branch in Sourcetree and deleting it, letting the UI take out the reference when it sees the remote branch has been deleted.
Today I discovered the git command for removing old remote branch references it and it’s fairly simple:
git remote prune <remote name>
Naturally because this is git, there’s also another way of invoking it – I wouldn’t be surprised if there were other ways too! According to the documentation, the following does exactly the same as the command above.
git fetch --prune <remote name>
Alternatively, there is a configuration you can set, so that every fetch will prune branches. This way you won’t ever have to worry about pruning branches ever again!
git config --global fetch.prune true
And this is what I love about software development:
- Not knowing how to do the thing.
- Learning how to do the thing.
- Making the thing happen automatically.
- Forgetting how to do the thing.