threads / discuss / 58319

[Question] How to know which branch(ref) is the latest updated branch?

Subject: [Question] How to know which branch(ref) is the latest updated branch?

## tl;dr

3 messages between Aug 18, 2022 and Aug 18, 2022.

replies: 2people: 3as markdown or json

Dan Pristupov· Aug 18, 2022, 14:30 UTC · re: lilinchao@oschina.cn · lore

Re: [Question] How to know which branch(ref) is the latest updated branch?

You can use `for-each-ref` for that. For example:

``` git for-each-ref --count=1 --sort='-authordate' refs/heads ```

https://git-scm.com/docs/git-for-each-ref#_examples has an example how to get 3 recent tags

Junio C Hamano· Aug 18, 2022, 17:08 UTC · re: lilinchao@oschina.cn · lore

Re: [Question] How to know which branch(ref) is the latest updated branch?

"lilinchao@oschina.cn" <lilinchao@oschina.cn> writes:
> In a git based workflow, there are usually many active branches.
> So, is there a convenient way to quickly know which branch is the
> latest updated?

These days "git branch" has "--sort" option, inherited from "for-each-ref", so

    git branch --sort=-committerdate
lists them from the most-recently-committed [*].
HOWEVER.

There is no way to sort on the time when each branch was last updated. You may do

    git branch newbranch HEAD@{2.years.ago}

to create a new branch (i.e. it is the last updated branch) that points at a commit that existed 2 years ago (hence it would be at least 2 years old, possibly more). If for-each-ref learns a new placeholder %(reflogtime) that can be used to represent the timestamp of the latest reflog entry, you should be able to sort by the time when branch was last updated, but not until then.

[Footnote]
I have this handy alias
    [alias]
    notyet = branch --no-merged jch --no-merged seen --sort=-committerdate '??/*'

to remind me of topics that are not yet in my integration branches while rebuilding them.

In the end result, 'seen' is supposed to include "everything I saw and found possibly interesting", and 'jch' is supposed to be a subset of it, but explicitly saying "show branches that are not in either of these two" helps while rebuilding them (and I do so a few times a day).

← back to recent threads