Member-only story

How to monitor and clean up old branches in the repository?

Amir Kamali
2 min readMay 24, 2021

--

As an engineering manager, part of my tasks has been looking after repositories and make sure only active branches are in the remote origin.

If you have not established the git-flow, you can establish a culture to delete old branches and remind people to delete branches.

To get started we’ll be using git for-each-ref command

This command will allow you to take a look at entries in your git

Filtering refs

You can filter the results to only display remote branches by specifying the ref path:
git for-each-ref refs/remotes/

Formatting & Sorting the results

You can format the output by using —-format

In case you’d like to get the results based on branch authors you can use
-authorname switch

Find the oldest branches and authors

If you’d like to sort the result to find oldest branches you can sort by -commiterdate switch:

git for-each-ref — sort=-committerdate refs/remotes/ — format “%(committerdate) %(authorname) %(refname)”

--

--

Amir Kamali
Amir Kamali

Written by Amir Kamali

Application Architect, Apple | ex. Director of Mobile & OTT at AMC Networks, ex. Engineering Manager at Tile / Life360

No responses yet