Congrats on reaching the end of week one!
It’s Friday, so let’s end with a quick win:
git branch -r . Marvel at all the old tracking branches that have been left in your local repo.
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.
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 .
- Maybe bug your coworkers to do 4 and 5, too.
- Enjoy the weekend!
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
I have a git cleanup command that does this.
git gc is also an useful thing todo when pruning.
Easy since we use Gerrit and hence no common Git patterns with branches, but did manage to delete one remote. (And not a fan of Gerrit)
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.
That was an easy win since we usually clean them up as we go. If you are using GitHub, I recommend you turn this option in settings:
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.
Got to this one I had a bunch of stale branches pushed up that had some experimental changes that I wanted CI to chew through