@matheusbsbs / matheus-bagliano / commits / dccadad736
Fork 0

git-worktree.txt: discuss branch-based vs. throwaway worktrees

By default, `git worktree add` creates a new worktree associated with a particular branch (which may have been created automatically if not specified explicitly on the command-line). It is also convenient to create throwaway worktrees not associated with any branch, which can be handy when making experimental changes or doing testing. However, the latter use-case may not be obvious to newcomers since the high-level description of worktrees talks only about checking out "more than one branch at a time". Therefore, enhance the description to to discuss both use-cases. A secondary goal of highlighting the distinction between branch-based and throwaway worktrees is to help newcomers understand that the simplest form `git worktree add <path>` automatically creates a new branch. Stating this early in the description, may help newcomers avoid creating branches without realizing they are doing so, and later wondering why `git branch --list` shows branches the user did not intentionally create. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Sep 6, 2020 at 20:02 UTC dccadad736c801e924c7c14e8c6bd1a6e15e70e5
1 file changed +12
Documentation/git-worktree.txt
+12
@@ -31,6 +31,18 @@ A repository has one main working tree (if it's not a
31 bare repository) and zero or more linked working trees. When you are done
32 with a linked working tree, remove it with `git worktree remove`.
33
34 +In its simplest form, `git worktree add <path>` automatically creates a
35 +new branch whose name is the final component of `<path>`, which is
36 +convenient if you plan to work on a new topic. For instance, `git
37 +worktree add ../hotfix` creates new branch `hotfix` and checks it out at
38 +path `../hotfix`. To instead work on an existing branch in a new working
39 +tree, use `git worktree add <path> <branch>`. On the other hand, if you
40 +just plan to make some experimental changes or do testing without
41 +disturbing existing development, it is often convenient to create a
42 +'throwaway' working tree not associated with any branch. For instance,
43 +`git worktree add -d <path>` creates a new working tree with a detached
44 +`HEAD` at the same commit as the current branch.
45 +
46 If a working tree is deleted without using `git worktree remove`, then
47 its associated administrative files, which reside in the repository
48 (see "DETAILS" below), will eventually be removed automatically (see