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

Re: GIT_DIR output from git worktree list

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Dec 8, 2020, 19:27 UTC
Message-ID
<CAPig+cQad_yyVgwQQ-NZyy7SergM-fUMeMAm9RsV4zEqNt9TDg@mail.gmail.com>
In-Reply-To
<A462326B-505D-4A92-B789-21BB8FE6AA16@gmail.com>
On Mon, Dec 7, 2020 at 2:28 AM Ganriel Nützi <gnuetzi@gmail.com> wrote:
Show 5 quoted lines
> As of your rational, wouldn‘t it be good anyway to have a file
> „worktree“ inside the .git dir (of the worktree) containing the path
> to the main worktree? So to speak any worktree always has a .git dir
> with a back link to its main worktree (the existence of the git dir
> might pose other problems?)

I'm having trouble understanding your proposal. Secondary worktrees don't have a .git/ directory; instead they have a "gitfile" named .git which is just a pointer to the worktree's administrative directory within the repository (specifically, <repo>/worktrees/<id>/, where <repo> might be a bare repository or the .git/ directory of the main worktree).

So a secondary worktree's back-link is a pointer into the repository; it's not necessarily pointing at the main worktree, as you discovered and reported in the email which started this thread.

What I was suggesting was that it might be the case that the only way to solve this would be to store the location of the main worktree somewhere within <repo> in some file, and then `git worktree list` would consult that file to learn the location of the main worktree. This is complicated by the fact that that file would have to be updated automatically if the main worktree directory is ever moved. It also needs to be done in such a way that it is easy for other Git implementations to understand and not trip over.

So, it's certainly possible, but it's something which requires more thought, and there might be alternate and better solutions I'm overlooking.

Previous: Ganriel NütziNext: Duy Nguyen
Message 7 of 9 in “GIT_DIR output from git worktree list”
  1. Gabriel NütziSep 29, 2020
  2. Eric SunshineSep 30, 2020
  3. Gabriel NütziSep 30, 2020
  4. Eric SunshineSep 30, 2020
  5. Eric SunshineDec 7, 2020
  6. Ganriel NütziDec 7, 2020
  7. Eric SunshineDec 8, 2020
  8. Duy NguyenDec 9, 2020
  9. Eric SunshineDec 13, 2020

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.