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

some apparent inaccuracies in "man git-worktree"

From
Robert P. J. Day <rpjday@crashcourse.ca>
Date
Nov 14, 2017, 08:43 UTC
Message-ID
<alpine.LFD.2.21.1711140324580.12112@localhost.localdomain>
  more annoying pedantry (but you're used to that by now, right?) ...
from "man git-worktree", there seem to be some inaccuracies in the
SYNOPSIS regarding the "add" subcommand:
  git worktree add \
    [-f] [--detach] [--checkout] [--lock] [-b <new-branch>] <path> [<branch>]
  first, there's no mention of "-B" in that SYNOPSIS, even though it's
explained further down the man page.
  next, the SYNOPSIS seems misleading as it doesn't make clear that
the options -b, -B and --detach are mutually exclusive, which is made
clear in the worktree.c source:
    if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
            die(_("-b, -B, and --detach are mutually exclusive"));
and, to some extent, further down the man page:
  "If <branch> is omitted and neither -b nor -B nor --detach used,
   then, as a convenience, a new branch based at HEAD is created
   automatically, as if -b $(basename <path>) was specified."
  finally (and maybe i'm just not reading carefully enough), it's not
clear what happens if you add a worktree at a given commit without
specifying *any* of -b, -B or --detach. the obvious result should be a
new worktree checked out at a detached HEAD and, interestingly, if i
do that, then from the main tree, i see:
  $ git worktree list
  /home/rpjday/k/git   516fb7f2e73d [master]
  /home/rpjday/k/temp  c470abd4fde4 (detached HEAD)
  $
but from within the worktree, if i ask for the status, i see only:
  $ git status
  Not currently on any branch.
  nothing to commit, working tree clean
  $

where i would normally have expected to see "detached HEAD", is there a reason that's not displayed?

rday
-- 
========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================
Next: Eric Sunshine
Message 1 of 4 in “some apparent inaccuracies in "man git-worktree"”
  1. Robert P. J. DayNov 14, 2017
  2. Eric SunshineNov 14, 2017
  3. Robert P. J. DayNov 14, 2017
  4. Jonathan NiederNov 21, 2017

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.