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

[PATCH] switch: mention the --detach option when dying due to lack of a branch

From
Alex Henrie <alexhenrie24@gmail.com>
Date
Feb 23, 2022, 07:31 UTC
Message-ID
<20220223073125.640133-1-alexhenrie24@gmail.com>

Users who are accustomed to doing `git checkout <tag>` assume that `git switch <tag>` will do the same thing. Inform them of the --detach option so they aren't left wondering why `git switch` doesn't work but `git checkout` does.

Signed-off-by: Alex Henrie <alexhenrie24@gmail.com>
---
 builtin/checkout.c | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/builtin/checkout.c b/builtin/checkout.c
index d9b31bbb6d..10a035feed 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -1398,6 +1398,10 @@ static void die_expecting_a_branch(const struct branch_info *branch_info)
 	struct object_id oid;
 	char *to_free;
 
+	if (advice_enabled(ADVICE_DETACHED_HEAD))
+		advise(_("The specified commit is not a local branch.\n"
+			 "If you want to enter detached head mode, try again with the --detach option."));
+
 	if (dwim_ref(branch_info->name, strlen(branch_info->name), &oid, &to_free, 0) == 1) {
 		const char *ref = to_free;
 
-- 
2.35.1
Next: Junio C Hamano
Message 1 of 5 in “switch: mention the --detach option when dying due to lack of a branch”
  1. switch: mention the --detach option when dying due to lack of a branchAlex Henrie, Feb 23, 2022
  2. Junio C HamanoFeb 23, 2022
  3. Alex HenrieFeb 23, 2022
  4. Ævar Arnfjörð BjarmasonFeb 23, 2022
  5. Alex HenrieFeb 24, 2022

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.