git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 18, 2022, 17:08 UTC
Message-ID
<xmqqa681qy2k.fsf@gitster.g>
In-Reply-To
<2022081818034939145210@oschina.cn>
"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).

Previous: Dan Pristupov
Message 3 of 3 in “[Question] How to know which branch(ref) is the latest updated branch?”
  1. lilinchao@oschina.cnAug 18, 2022
  2. Dan PristupovAug 18, 2022
  3. Junio C HamanoAug 18, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.