threads / discuss / 65137

Feature request: support listing worktrees sorted by creation time

Subject: Feature request: support listing worktrees sorted by creation time

## tl;dr

6 messages between Mar 5, 2026 and Mar 6, 2026.

replies: 5people: 4as markdown or json

Norbert Kiesel· Mar 5, 2026, 07:14 UTC · lore
Hi!

I have multiple repos with more than 20 worktrees, and sometimes forget the name of a recently added worktree. Therefore it would really be nice if I could use something like ‘git worktree list —created’ to list them by their creation timestamp. Is that something that makes sense to you as well? I could also create a pull request for this if you would like it.

Best,
  Norbert
Johannes Sixt· Mar 5, 2026, 07:35 UTC · re: Norbert Kiesel · lore

Re: Feature request: support listing worktrees sorted by creation time

Am 05.03.26 um 08:14 schrieb Norbert Kiesel:
Show 6 quoted lines
> I have multiple repos with more than 20 worktrees, and sometimes
> forget the name of a recently added worktree. Therefore it would
> really be nice if I could use something like ‘git worktree list
> —created’ to list them by their creation timestamp. Is that something
> that makes sense to you as well? I could also create a pull request
> for this if you would like it.

I don't think this is warranted as a feature for a special-purpose use-case. Assuming you don't have spaces in your worktree directory names,

  git worktree list | cut -d' ' -f1 | xargs ls -ldtr

lists the worktree directories by modification time. The last is the one that was modified most recently. That should help your memory.

-- Hannes
Norbert Kiesel· Mar 5, 2026, 07:41 UTC · re: Johannes Sixt · lore

Re: Feature request: support listing worktrees sorted by creation time

My understanding is that the timestamp of the base worktree directories is updated whenever a new file is created in that directory, and thus this will not preserve the worktree creation time. Therefore, I would like to have an explicit creation timestamp in the worktree metadata.

On Wed, Mar 4, 2026 at 11:35 PM Johannes Sixt <j6t@kdbg.org> wrote:
Show 18 quoted lines
>
> Am 05.03.26 um 08:14 schrieb Norbert Kiesel:
> > I have multiple repos with more than 20 worktrees, and sometimes
> > forget the name of a recently added worktree. Therefore it would
> > really be nice if I could use something like ‘git worktree list
> > —created’ to list them by their creation timestamp. Is that something
> > that makes sense to you as well? I could also create a pull request
> > for this if you would like it.
> I don't think this is warranted as a feature for a special-purpose
> use-case. Assuming you don't have spaces in your worktree directory names,
>
>   git worktree list | cut -d' ' -f1 | xargs ls -ldtr
>
> lists the worktree directories by modification time. The last is the one
> that was modified most recently. That should help your memory.
>
> -- Hannes
>
Junio C Hamano· Mar 5, 2026, 15:50 UTC · re: Norbert Kiesel · lore

Re: Feature request: support listing worktrees sorted by creation time

Norbert Kiesel <nkiesel@gmail.com> writes:
Show 6 quoted lines
> I have multiple repos with more than 20 worktrees, and sometimes
> forget the name of a recently added worktree. Therefore it would
> really be nice if I could use something like ‘git worktree list
> —created’ to list them by their creation timestamp. Is that something
> that makes sense to you as well? I could also create a pull request
> for this if you would like it.

I do not think we have any _record_ of when each of these worktrees was created, so this is not a realistic request.

The output from "git worktree list" may be more than 20 lines, but isn't your terminal taller than 20 lines ;-)?

Since very early days of Git, we have created .git/description file that is not used very much (I think it is shown in gitweb). Perhaps worktree should have an equivalent in per-worktree part of their .git/ directory and "git worktree list --verbose" can use its contents in addition to the additional pieces information it already shows, or something like that, perhaps?

Norbert Kiesel· Mar 5, 2026, 23:36 UTC · re: Junio C Hamano · lore

Re: Feature request: support listing worktrees sorted by creation time

Wrote a Zsh script that uses the "directory create time" but when a worktree is moved then that will be updated. So would still like to have `git worktree add` store the current timestamp somewhere.

```zsh #!/bin/zsh # List git worktrees with creation timestamps, sorted oldest to newest

wt_path="" branch="" typeset -a ts_arr wt_arr br_arr

flush() {
    [[ -z $wt_path ]] && return
    local epoch=$(stat -f '%B' "$wt_path" 2>/dev/null)
    ts_arr+=("${epoch:-0}")
    wt_arr+=("$wt_path")
    br_arr+=("${branch:-(detached)}")
    wt_path="" branch=""
}
while IFS= read -r line; do
    case $line in
        worktree\ *)  flush; wt_path=${line#worktree } ;;
        branch\ *)    branch=${line#branch refs/heads/} ;;
        detached)     branch="(detached)" ;;
        "")           flush ;;
    esac
done < <(git worktree list --porcelain)
flush
# Find max branch width for column alignment
integer max_br=0
for br in "${br_arr[@]}"; do
    (( ${#br} > max_br )) && max_br=${#br}
done

# Print first entry (main worktree) always first printf "%s %-${max_br}s %s\n" "$(date -r "${ts_arr[1]}" +"%Y-%m-%d")" "${br_arr[1]}" "${wt_arr[1]}"

# Collect remaining entries prefixed with epoch for numeric sort
typeset -a rest_lines
for (( i=2; i<=${#ts_arr}; i++ )); do
    rest_lines+=("${ts_arr[$i]}  $(printf "%-${max_br}s  %s"
"${br_arr[$i]}" "${wt_arr[$i]}")")
done
# Sort numerically by epoch, then replace epoch with formatted date
(( ${#rest_lines} > 0 )) && print -l "${(on)rest_lines[@]}" | while
IFS= read -r line; do
    epoch=${line%% *}
    printf "%s  %s\n" "$(date -r "$epoch" +"%Y-%m-%d")" "${line#*  }"
done
```
On Thu, Mar 5, 2026 at 7:50 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 22 quoted lines
>
> Norbert Kiesel <nkiesel@gmail.com> writes:
>
> > I have multiple repos with more than 20 worktrees, and sometimes
> > forget the name of a recently added worktree. Therefore it would
> > really be nice if I could use something like ‘git worktree list
> > —created’ to list them by their creation timestamp. Is that something
> > that makes sense to you as well? I could also create a pull request
> > for this if you would like it.
>
> I do not think we have any _record_ of when each of these worktrees
> was created, so this is not a realistic request.
>
> The output from "git worktree list" may be more than 20 lines, but
> isn't your terminal taller than 20 lines ;-)?
>
> Since very early days of Git, we have created .git/description file
> that is not used very much (I think it is shown in gitweb).  Perhaps
> worktree should have an equivalent in per-worktree part of their
> .git/ directory and "git worktree list --verbose" can use its
> contents in addition to the additional pieces information it already
> shows, or something like that, perhaps?
Erik Cervin Edin· Mar 6, 2026, 13:02 UTC · re: Junio C Hamano · lore

Re: Feature request: support listing worktrees sorted by creation time

On 26/03/05 07:50AM, Junio C Hamano wrote:
Show 8 quoted lines
> 
> Since very early days of Git, we have created .git/description file
> that is not used very much (I think it is shown in gitweb).  Perhaps
> worktree should have an equivalent in per-worktree part of their
> .git/ directory and "git worktree list --verbose" can use its
> contents in addition to the additional pieces information it already
> shows, or something like that, perhaps?
> 

I think that sounds like a nice addition. I frequently name the worktree to encode the intent of the worktree, but that can be a bit clunky. Having a way to describe it and/or metadata sounds nice!

← back to recent threads