{"thread":{"id":"58319","subject":"[Question] How to know which branch(ref) is the latest updated branch?","startedAt":"2022-08-18T10:04:57Z","lastAt":"2022-08-18T17:16:17Z","messageCount":3,"participants":["lilinchao@oschina.cn","Dan Pristupov","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"461411","messageId":"2022081818034939145210@oschina.cn","threadId":"58319","inReplyTo":null,"subject":"[Question] How to know which branch(ref) is the latest updated branch?","fromName":"lilinchao@oschina.cn","fromEmail":"lilinchao@oschina.cn","sentAt":"2022-08-18T10:04:49Z","receivedAt":"2022-08-18T10:04:57Z","isPatch":false,"sender":{"key":"lilinchao@oschina.cn","avatar":null},"body":"In a git based workflow, there are usually many active branches.\nSo, is there a convenient way to quickly know which branch is the\nlatest updated?\n"},{"id":"461425","messageId":"09d5a345-af62-c411-8fb5-b489337ebc36@danil.cz","threadId":"58319","inReplyTo":"2022081818034939145210@oschina.cn","subject":"Re: [Question] How to know which branch(ref) is the latest updated branch?","fromName":"Dan Pristupov","fromEmail":"danil@danil.cz","sentAt":"2022-08-18T14:30:15Z","receivedAt":"2022-08-18T14:30:33Z","isPatch":false,"sender":{"key":"danil@danil.cz","avatar":"https://gravatar.com/avatar/0c17c2eda2eaabbcc09a02149bedaff23bc8894c7be16e6b25d6602abfc34243?d=mp&s=160"},"body":"You can use `for-each-ref` for that. For example:\n\n```\ngit for-each-ref --count=1 --sort='-authordate' refs/heads\n```\n\nhttps://git-scm.com/docs/git-for-each-ref#_examples has an example how \nto get 3 recent tags\n\n"},{"id":"461446","messageId":"xmqqa681qy2k.fsf@gitster.g","threadId":"58319","inReplyTo":"2022081818034939145210@oschina.cn","subject":"Re: [Question] How to know which branch(ref) is the latest updated branch?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-18T17:08:19Z","receivedAt":"2022-08-18T17:16:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"lilinchao@oschina.cn\" <lilinchao@oschina.cn> writes:\n\n> In a git based workflow, there are usually many active branches.\n> So, is there a convenient way to quickly know which branch is the\n> latest updated?\n\nThese days \"git branch\" has \"--sort\" option, inherited from \"for-each-ref\",\nso\n\n    git branch --sort=-committerdate\n\nlists them from the most-recently-committed [*].\n\nHOWEVER.\n\nThere is no way to sort on the time when each branch was last\nupdated.  You may do\n\n    git branch newbranch HEAD@{2.years.ago}\n\nto create a new branch (i.e. it is the last updated branch) that\npoints at a commit that existed 2 years ago (hence it would be at\nleast 2 years old, possibly more).  If for-each-ref learns a new\nplaceholder %(reflogtime) that can be used to represent the\ntimestamp of the latest reflog entry, you should be able to sort by\nthe time when branch was last updated, but not until then.\n\n\n[Footnote]\n\nI have this handy alias\n\n    [alias]\n    notyet = branch --no-merged jch --no-merged seen --sort=-committerdate '??/*'\n\nto remind me of topics that are not yet in my integration branches\nwhile rebuilding them.\n\nIn the end result, 'seen' is supposed to include \"everything I saw\nand found possibly interesting\", and 'jch' is supposed to be a\nsubset of it, but explicitly saying \"show branches that are not in\neither of these two\" helps while rebuilding them (and I do so a few\ntimes a day).\n"}]}