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

Re: GIT_WORK_TREE is not exported for post-checkout-hook

From
PSPhil Sainty <psainty@orcon.net.nz>
Date
Sep 25, 2026, 07:11 UTC
Message-ID
<a22c36b869d545cf3197f031a339c6b0@orcon.net.nz>
In-Reply-To
<xmqqqzisvpsq.fsf@gitster.g>
Hi Junio,
On 2026-09-17 09:39, Junio C Hamano wrote:
> The attached patch would export GIT_WORK_TREE when
> worktree exists and GIT_DIR would also be exported,

Thanks for looking at this. I've just tested your patch and it seems to me that discovery.worktree may not be (or at least may not /always/ be) the right value. With the patch I see the following in my script's environment:

      GIT_DIR=/path/to/repo/.git/worktrees/name
      GIT_WORK_TREE='.'

Moreover, I see the '.' value regardless of which sub- directory of the worktree I was in at the time.

"git rev-parse --show-toplevel" still returns the CWD (which may now be because it's the path for the explicit '.' value?)

I can see a few places in setup.c where that value is being set:

     ./setup.c:510:		setenv(GIT_WORK_TREE_ENVIRONMENT, ".", 1);
     ./setup.c:1213:		repo_discovery_set_worktree(discovery, ".");
     ./setup.c:1269:	repo_discovery_set_worktree(discovery, ".");
Previous: Junio C Hamano
Message 3 of 3 in “GIT_WORK_TREE is not exported for post-checkout-hook”
  1. Phil SaintySep 15, 2026
  2. Junio C HamanoSep 16, 2026
  3. Phil SaintySep 25, 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.