I sometimes work with source code repositories containing many branches, most of which are old and usually no longer relevant.
In these cases, the full list of branches from git branch is not very helpful. Is there a way to only list “active” branches? For example, only branches that received commits in the last n days? Ideally, the list would include the last commit date for each branch, and indicate if the branch is already fully merged.
P.S.:
I realize that this can also be solved by deleting “old” branches (as discussed e.g. in What to do with experimental non-merged git branches? ), but this may not always be practical or accepted on a given project.
You can use git-for-each-ref to get a list of all the local and tracking branches sorted in descending order by the committer date of the last commit like this:
This outputs eg.:
You can add
--count=mto get at most m branches, you can--sort=-authordateinstead of using the committer date, you can of course use different formats.for-each-refitself does not limit the result by date, this has to be scripted separately, but at least you have the dates from the commit object in hand.