From: Kiesel, Norbert Date: Fri, 05 Jun 2026 16:13:42 GMT Subject: Re: [PATCH] worktree: record creation time and free-form note Message-ID: In-Reply-To: Yes, we could look at the branch description instead of adding a worktree note/description. However, when I talked to some others, some of them told me that they use some worktrees more like a "group changes" where they then switch between some branches within the same worktree. And therefore, they wanted a separate worktree note. The "sort by last updated" sounds like a very nice idea. Again, similar to "ls -l --sort=time --time=modifiction" vs "ls -l --sort=time --time=creation" for GNU ls. So would you prefer to only support sorting by "last updated" or would you support multiple sort options: time created, time last updated, in addition to name? Best, Norbert On Fri, Jun 5, 2026 at 8:17 AM Phillip Wood wrote: > > Hi Norbert > > On 02/06/2026 22:40, Kiesel, Norbert wrote: > > > > Add per-worktree metadata so users can answer "what is this worktree > > for, and when did I make it?" without resorting to external notes. > > A couple of thoughts related to this > > Isn't "what is the worktree for" a property of the branch that's checked > out, not the worktree itself? We already have > branch..description to add a descritpion to a branch. If you > have a detached HEAD it is trickier though. > > I don't think I've ever wanted to know when a worktree was created. I > would find it useful to be able to sort worktrees by when they were last > updated (i.e. the reflog date of HEAD in each worktree) to see which > ones are stale though. > > Thanks > > Phillip > > > When `git worktree add` creates a linked worktree, it now writes a > > `created` file containing the unix timestamp. A new `--note ` > > option to `add`, and a new `git worktree annotate []` > > subcommand, store an optional free-form description in a `note` file > > next to the other administrative files. Passing `annotate` without a > > note clears it. The main worktree carries no metadata and cannot be > > annotated. > > > > `git worktree list` learns `--show-created` and `--show-note` for > > human-readable output, and `--sort=` (path or created, optionally > > prefixed with `-` to reverse) for ordering linked worktrees; the main > > worktree always stays first. Worktrees without a recorded timestamp > > (those created before this change) display as `created: unknown` and > > sort after timestamped ones. Porcelain output unconditionally emits > > `created` and `note` lines when the corresponding metadata is present. > > > > Tests cover add/annotate/list behaviour and the legacy-worktree case. > > The two existing porcelain assertions in t2402 are taught to strip the > > new `created` line so they continue to pass. > > > > Signed-off-by: Norbert Kiesel > > --- > > Documentation/git-worktree.adoc | 61 ++++++++++++- > > builtin/worktree.c | 152 +++++++++++++++++++++++++++++++- > > t/meson.build | 1 + > > t/t2402-worktree-list.sh | 10 ++- > > t/t2410-worktree-metadata.sh | 143 ++++++++++++++++++++++++++++++ > > worktree.c | 78 ++++++++++++++++ > > worktree.h | 23 +++++ > > 7 files changed, 459 insertions(+), 9 deletions(-) > > create mode 100755 t/t2410-worktree-metadata.sh > > > > diff --git a/Documentation/git-worktree.adoc b/Documentation/git-worktree.adoc > > index fbf8426cd9..200f3d7772 100644 > > --- a/Documentation/git-worktree.adoc > > +++ b/Documentation/git-worktree.adoc > > @@ -10,8 +10,11 @@ SYNOPSIS > > -------- > > [synopsis] > > git worktree add [-f] [--detach] [--checkout] [--lock [--reason ]] > > + [--note ] > > [--orphan] [(-b | -B) ] [] > > -git worktree list [-v | --porcelain [-z]] > > +git worktree annotate [] > > +git worktree list [-v | --porcelain [-z]] [--show-created] [--show-note] > > + [--sort=] > > git worktree lock [--reason ] > > git worktree move > > git worktree prune [-n] [-v] [--expire ] > > @@ -106,6 +109,15 @@ passed to the command. In the event the > > repository has a remote and > > command fails with a warning reminding the user to fetch from their remote > > first (or override by using `-f`/`--force`). > > > > +`annotate []`:: > > + > > +Set, replace, or clear a free-form note (description) on a linked worktree. > > +Useful for recording what a worktree was created for so it can be identified > > +later. With __, the worktree's note is set or replaced; without a note > > +argument, the existing note is cleared. The note for a worktree may also be > > +set at creation time with `git worktree add --note `. The main > > +worktree cannot be annotated. > > + > > `list`:: > > > > List details of each worktree. The main worktree is listed first, > > @@ -114,6 +126,20 @@ whether the worktree is bare, the revision > > currently checked out, the > > branch currently checked out (or "detached HEAD" if none), "locked" if > > the worktree is locked, "prunable" if the worktree can be pruned by the > > `prune` command. > > ++ > > +Each worktree's creation timestamp is recorded when it is created with > > +`git worktree add`. Worktrees created before this feature existed have no > > +recorded creation timestamp; for them, `list` reports `created: unknown` > > +in human output and omits the `created` line in `--porcelain` output. Pass > > +`--show-created` to include creation timestamps in human output. Worktrees > > +without a recorded timestamp sort last (or first when reversed) with > > +`--sort=created`. > > ++ > > +Pass `--show-note` to include any user-provided note in human output. In > > +`--porcelain` output, both `created` and `note` lines are emitted whenever > > +present. Use `--sort=` (where __ is `path` or `created`, > > +optionally prefixed with `-` to reverse) to order the linked worktrees; > > +the main worktree always remains first. > > > > `lock`:: > > > > @@ -286,6 +312,32 @@ _