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

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

From
RTRebecca Turner <rbt@fastmail.com>
Date
Oct 11, 2024, 01:12 UTC
Message-ID
<8f961645-2b70-4d45-a9f9-72e71c07bc11@app.fastmail.com>
It seems that `.git` is always stripped from the `git worktree list` output (including in `--porcelain` mode). This becomes relevant with bare repositories. Here is a bare repository functioning as expected:

$ mkdir bare1 $ cd bare1 $ git init --bare Initialized empty Git repository in /private/tmp/bare1/ $ git worktree list /private/tmp/bare1 (bare)

But if we create a bare repository in a directory named `.git`, `git worktree list` displays the parent directory as the worktree, even though `git status` doesn't recognize it as a worktree:

$ mkdir -p bare2/.git $ cd bare2/.git $ git init --bare Initialized empty Git repository in /private/tmp/bare2/.git/ $ git worktree list /private/tmp/bare2 (bare) $ cd /tmp/bare2 $ git status fatal: this operation must be run in a work tree

However, Git _will_ recognize the parent directory (/tmp/bare2) as a Git repository for the purposes of commands like `git rev-parse --git-dir`. I suspect this can be fixed in `get_main_worktree` by only stripping a `.git` suffix from the path if the main worktree is not bare.
Message 1 of 1 in “`git worktree list` when bare repository is named `.git`”
  1. Rebecca TurnerOct 11, 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.