How to Clean Up Local Git Branches That Are Gone from Remote
July 29, 2025
GitEver deleted a branch on GitHub or GitLab, but it's still hanging around on your local machine? 🤔 Here's a quick and easy way to tidy up your local repository and remove those old branches.
Script
# Update remote references
git fetch --prune
# Identify and delete local branches that no longer exist on remote
git branch -vv | grep 'gone]' | awk '{print $1}' | xargs git branch -D
And it's done!