Merge branch 'es/wt-add-detach'

"git worktree add" learns that the "-d" is a synonym to "--detach"
option to create a new worktree without being on a branch.

* es/wt-add-detach:
  git-worktree.txt: discuss branch-based vs. throwaway worktrees
  worktree: teach `add` to recognize -d as shorthand for --detach
  git-checkout.txt: document -d short option for --detach
This commit is contained in:
Junio C Hamano 2020-09-18 17:58:04 -07:00
commit 45f462b5c5
3 changed files with 15 additions and 1 deletions

View file

@ -198,6 +198,7 @@ Use `--no-guess` to disable this.
Create the new branch's reflog; see linkgit:git-branch[1] for
details.
-d::
--detach::
Rather than checking out a branch to work on it, check out a
commit for inspection and discardable experiments.

View file

@ -32,6 +32,18 @@ A repository has one main working tree (if it's not a
bare repository) and zero or more linked working trees. When you are done
with a linked working tree, remove it with `git worktree remove`.
In its simplest form, `git worktree add <path>` automatically creates a
new branch whose name is the final component of `<path>`, which is
convenient if you plan to work on a new topic. For instance, `git
worktree add ../hotfix` creates new branch `hotfix` and checks it out at
path `../hotfix`. To instead work on an existing branch in a new working
tree, use `git worktree add <path> <branch>`. On the other hand, if you
just plan to make some experimental changes or do testing without
disturbing existing development, it is often convenient to create a
'throwaway' working tree not associated with any branch. For instance,
`git worktree add -d <path>` creates a new working tree with a detached
`HEAD` at the same commit as the current branch.
If a working tree is deleted without using `git worktree remove`, then
its associated administrative files, which reside in the repository
(see "DETAILS" below), will eventually be removed automatically (see
@ -164,6 +176,7 @@ To remove a locked working tree, specify `--force` twice.
exists. `-B` overrides this safeguard, resetting `<new-branch>` to
`<commit-ish>`.
-d::
--detach::
With `add`, detach `HEAD` in the new working tree. See "DETACHED HEAD"
in linkgit:git-checkout[1].

View file

@ -555,7 +555,7 @@ static int add(int ac, const char **av, const char *prefix)
N_("create a new branch")),
OPT_STRING('B', NULL, &new_branch_force, N_("branch"),
N_("create or reset a branch")),
OPT_BOOL(0, "detach", &opts.detach, N_("detach HEAD at named commit")),
OPT_BOOL('d', "detach", &opts.detach, N_("detach HEAD at named commit")),
OPT_BOOL(0, "checkout", &opts.checkout, N_("populate the new working tree")),
OPT_BOOL(0, "lock", &opts.keep_locked, N_("keep the new working tree locked")),
OPT__QUIET(&opts.quiet, N_("suppress progress reporting")),