From: Eric Sunshine <email@example.com> To: firstname.lastname@example.org Cc: "Pratyush Yadav" <email@example.com>, "SZEDER Gábor" <firstname.lastname@example.org>, "Junio C Hamano" <email@example.com>, "Eric Sunshine" <firstname.lastname@example.org> Subject: [PATCH 3/3] git-worktree.txt: discuss branch-based vs. throwaway worktrees Date: Fri, 4 Sep 2020 03:07:03 -0400 [thread overview] Message-ID: <email@example.com> (raw) In-Reply-To: <firstname.lastname@example.org> 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 unwanted new branches without being aware that they are doing so, and later wondering why `git branch --list` shows branches the user did not intentionally create. Signed-off-by: Eric Sunshine <email@example.com> --- Documentation/git-worktree.txt | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt index d252b6873b..1449491c1b 100644 --- a/Documentation/git-worktree.txt +++ b/Documentation/git-worktree.txt @@ -31,6 +31,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 -- 220.127.116.118.gf4bc123cb7
next prev parent reply other threads:[~2020-09-04 7:08 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-09-04 7:07 [PATCH 0/3] worktree: add -d shorthand for --detach & improve documentation Eric Sunshine 2020-09-04 7:07 ` [PATCH 1/3] git-checkout.txt: document -d short option for --detach Eric Sunshine 2020-09-04 7:07 ` [PATCH 2/3] worktree: add " Eric Sunshine 2020-09-04 7:07 ` Eric Sunshine [this message] 2020-09-06 21:58 ` [PATCH 0/3] worktree: add -d shorthand for --detach & improve documentation Junio C Hamano 2020-09-07 0:02 ` [PATCH v2 0/3] worktree: teach `add` -d " Eric Sunshine 2020-09-07 0:02 ` [PATCH v2 1/3] git-checkout.txt: document -d short option for --detach Eric Sunshine 2020-09-07 0:02 ` [PATCH v2 2/3] worktree: teach `add` to recognize -d as shorthand " Eric Sunshine 2020-09-07 0:02 ` [PATCH v2 3/3] git-worktree.txt: discuss branch-based vs. throwaway worktrees Eric Sunshine
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://vger.kernel.org/majordomo-info.html * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --firstname.lastname@example.org \ --email@example.com \ --subject='Re: [PATCH 3/3] git-worktree.txt: discuss branch-based vs. throwaway worktrees' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Code repositories for project(s) associated with this inbox: https://80x24.org/mirrors/git.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).