Run git branch -r . Marvel at all the old tracking branches that have been left in your local repo.
Run git remote prune origin to delete the local tracking branches that don’t exist on origin anymore. You might want to throw a --dry-run on there to confirm that git is going to do the right thing.
Re-run git branch -r . Better, right?
Now that your local repo is clean, take a look at the branches on origin by running git ls-remote --heads origin .
Delete any of your branches that are no longer needed with git push origin --delete old_branch .
Easy win, I clean up all my branches after every remote merge of a PR
From my bash profile (should still work, I’m not maintaining this repo anymore since I moved it to a private one because I added shortcuts for non-public projects):
Warning: I’m far away from being a bash or git expert! There is a better way for sure
Done. I generally delete branches after they’ve been merged into main, but there are still a lot of extra ones hanging out there. I got rid of a couple dozen or so.
You can also find out stale branches on https://github.com/<owner>/<repo>/branches/stale. It’s a nice way to pop discussions around old branches that may be POC that never got shipped.