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

Re: `git worktree list` when bare repository is named `.git`

From
RTRebecca Turner <rbt@fastmail.com>
Date
Oct 11, 2024, 04:59 UTC
Message-ID
<444a412d-bf4c-4bbe-8250-18d8bc86fd21@app.fastmail.com>
In-Reply-To
<D4SO70M9Z1QI.1AC4QF9ZG8T4L@pm.me>
> The actual bare repository can be the directory, in a .git directory,
> or in any other directory (as long as it has a .git file that points
> to the actual bare repository). The directory will still be considered a
> bare repository.
Perhaps your example got scrambled, but I can't quite reproduce it:

$ mkdir -p repo/.bare $ cd repo/.bare $ git init --bare Initialized empty Git repository in /private/tmp/repo/.bare/ $ git worktree list /private/tmp/repo/.bare (bare) $ cd .. $ git worktree list fatal: not a git repository (or any of the parent directories): .git $ echo 'gitdir: .bare' >.git $ git worktree list /private/tmp/repo/.bare (bare)

It seems like the $GIT_DIR is shown in the worktree list here, and when I add a `.git` file pointing to `.bare` manually, that doesn't get listed. (Which I suppose makes sense, because it's not a `git-worktree(1)` worktree, but still seems a little bit odd?)

Show 8 quoted lines
> For the purposes of `git worktree list`, the `.git` suffix **should not** be
> shown. You should never try to use `git worktree list` to get the actual path
> of the repository, the docs give the following warning:
>
>     See gitrepository-layout[5] for more information. The rule of thumb is do
>     not make any assumption about whether a path belongs to $GIT_DIR or
>     $GIT_COMMON_DIR when you need to directly access something inside $GIT_DIR.
>     Use git rev-parse --git-path to get the final path.

I understood this note to be talking about paths _within_ the `$GIT_DIR` or `$GIT_COMMON_DIR` itself; I see no reason why `git worktree list` wouldn't list a bare repository _consistently_ as either the `$GIT_DIR` or the parent of the `$GIT_DIR`.

What I'd like to do is get the path of the worktree so that I can move it. `git worktree list` gives me this information _except_ for bare repositories in directories named `.git`. I'm happy to have a special case for this, but I'd like to understand the principle here.

Maybe I'm just not supposed to name a bare repository `.git`? The `gitrepository-layout(5)` page does seem to imply this is mutually exclusive with bare repositories:

Show 7 quoted lines
> A Git repository comes in two different flavours:
>
> •    a .git directory at the root of the working tree;
>
> •    a <project>.git directory that is a bare repository (i.e. without its
>      own working tree), that is typically used for exchanging histories with
>      others by pushing into it and fetching from it.
Thanks for your help!
Previous: Caleb WhiteNext: Caleb White
Message 2 of 7 in “Re: `git worktree list` when bare repository is named `.git`”
  1. Caleb WhiteOct 11, 2024
  2. Rebecca TurnerOct 11, 2024
  3. Caleb WhiteOct 11, 2024
  4. Rebecca TurnerOct 11, 2024
  5. Caleb WhiteOct 11, 2024
  6. Patrick CallahanOct 11, 2024
  7. Rebecca TurnerOct 21, 2024

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.