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

[RFC] worktree: add lifecycle hooks

From
Maciej Ciemborowicz <maciej.ciemborowicz@gmail.com>
Date
Sep 20, 2026, 17:33 UTC
Message-ID
<20260920173333.1606-1-maciej.ciemborowicz@gmail.com>
Hello,
I'd like to discuss adding native hooks for worktree lifecycle events.

Git currently invokes `post-checkout` after `git worktree add` when a checkout is performed. This makes it possible to detect some worktree creation cases indirectly. There does not appear to be a native hook for other worktree lifecycle operations such as:

    git worktree add
    git worktree remove
    git worktree move
    git worktree lock
    git worktree unlock
    git worktree prune

As a result, tools which want to react to these operations have to wrap `git worktree` or compare the worktree state before and after a command. They cannot observe an invocation which bypasses their wrapper.

One concrete use case is git-hooks-ext, which provides higher-level events for Git operations. It currently has to implement worktree events by wrapping `git worktree` and comparing the output of `git worktree list --porcelain` before and after the command.

Would it make sense for Git to expose worktree lifecycle events directly?
One possibility would be separate post-operation hooks such as:
    post-worktree-add
    post-worktree-remove
    post-worktree-move
    post-worktree-lock
    post-worktree-unlock

Another possibility would be a single hook, similar in spirit to `reference-transaction`, which reports worktree lifecycle changes. An illustrative payload could look like:

    add    <path>
    remove <path>
    move   <old-path> <new-path>
    lock   <path>
    unlock <path>
    prune  <path>

A single hook may be useful for operations such as `git worktree prune`, where one command can remove multiple administrative entries. It could also leave room for `git worktree repair`, although I am unsure whether repair belongs to the same interface.

For the use case I have in mind, these hooks would only need to notify observers after a successful operation. They would not need to veto the operation.

Before attempting an implementation, I'd like to know whether this would fit Git's hook model, and whether a single lifecycle hook or individual operation hooks would be preferable. I would also appreciate guidance on whether a stable worktree identifier should be exposed in addition to the path.

Thanks, Maciej Ciemborowicz

Next: Kristoffer Haugsbakk
Message 1 of 2 in “[RFC] worktree: add lifecycle hooks”
  1. Maciej CiemborowiczSep 20, 2026
  2. Kristoffer HaugsbakkSep 20, 2026

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.