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 .
I didn’t really have local stale branches, because I clean those regularly, but remote it was a mess!
I found 6 year old branches, branches by people who’ve long since left the company.
Feels good to clean those up. I also passed along the message to the team. Thanks, see you Monday!
I ran through a couple of repos and indeed found a lot of branches. Many of them were from the all-contributors bot I use to add contributors to my README.
Here’s a one-liner to just delete the branches including all-contributors (or any regex, actually!)
This is where my imposter syndrome kicks in I work with just the master branch, for years now and served me well to be honest. Keeps it all plain and simple and forces me to work on one feature at a time.
I have a lot of local branches. Some of them are needed and cannot be merged. The others were really stale and now are gone. Yay!
I use https://git-fork.com/ that gives you quick insights into the branches (both local and remote) if you want to see the diff.