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

Re: Difficulties in advertising a new branch to git newbies

From
Jeff King <peff@peff.net>
Date
Jan 30, 2007, 23:10 UTC
Message-ID
<20070130231015.GB10075@coredump.intra.peff.net>
In-Reply-To
<87odognuhl.wl%cworth@cworth.org>
On Tue, Jan 30, 2007 at 12:13:26PM -0800, Carl Worth wrote:
Show 13 quoted lines
> Also, if I'm willing to assume (or insist) that users have git 1.5 or
> newer, it'd be nice to be able to drop the "-b build" thing thanks to
> the new detached HEAD support. But if I suggest doing just:
> 
> 		git checkout origin/proposed-fix
> 
> the user is presented with the following message which is much more
> scary than useful in this situation:
> 
> 	warning: you are not on ANY branch anymore.
> 	If you meant to create a new branch from the commit, you need -b to
> 	associate a new branch with the wanted checkout.  Example:
> 	  git checkout -b <new_branch_name> origin/proposed-fix
I don't see any reason why we can't scare the user when making a commit,
instead of just checkout out to look around. Something like the patch
below. It needs a few things:
  - remove the old checkout message
  - we wrap the colorization over the multi-line message. Probably a
    color_printf_lines() function should be added
  - if colorization is enabled, print it using color.status.warning
    (default to red).

I'm happy to make all those happen if there is interest (Junio, please comment).

diff --git a/wt-status.c b/wt-status.c
index 5567868..285c824 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -22,6 +22,12 @@ static const char use_add_rm_msg[] =
 "use \"git add/rm <file>...\" to update what will be committed";
 static const char use_add_to_include_msg[] =
 "use \"git add <file>...\" to include in what will be committed";
+static const char detach_warn[] =
+"# Any commits you make may become inaccessible if you checkout\n"
+"# another branch. To save them, you may create a new branch\n"
+"# from the current HEAD using:\n"
+"#   git checkout -b <new_branch_name>\n"
+"#";
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -303,16 +309,13 @@ void wt_status_print(struct wt_status *s)
 	s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
 
 	if (s->branch) {
-		const char *on_what = "On branch ";
-		const char *branch_name = s->branch;
-		if (!strncmp(branch_name, "refs/heads/", 11))
-			branch_name += 11;
-		else if (!strcmp(branch_name, "HEAD")) {
-			branch_name = "";
-			on_what = "Not currently on any branch.";
+		const char *c = color(WT_STATUS_HEADER);
+		if (!strncmp(s->branch, "refs/heads/", 11))
+			color_printf_ln(c, "# On branch %s", s->branch+11);
+		else {
+			color_printf_ln(c, "# Not currently on any branch.");
+			color_printf_ln(c, detach_warn);
 		}
-		color_printf_ln(color(WT_STATUS_HEADER),
-			"# %s%s", on_what, branch_name);
 	}
 
 	if (s->is_initial) {
Previous: Matthias LederhoferNext: Junio C Hamano
Message 9 of 50 in “Difficulties in advertising a new branch to git newbies”
  1. Carl WorthJan 30, 2007
  2. Jakub NarebskiJan 30, 2007
  3. Yann DirsonJan 30, 2007
  4. Jakub NarebskiJan 30, 2007
  5. Junio C HamanoJan 30, 2007
  6. Jakub NarebskiJan 30, 2007
  7. Matthias LederhoferJan 30, 2007
  8. Matthias LederhoferJan 30, 2007
  9. Jeff KingJan 30, 2007
  10. Junio C HamanoJan 31, 2007
  11. Nicolas PitreJan 31, 2007
  12. Jeff KingJan 31, 2007
  13. Nicolas PitreJan 31, 2007
  14. Jeff KingJan 31, 2007
  15. Nicolas PitreJan 31, 2007
  16. Jeff KingJan 31, 2007
  17. Junio C HamanoJan 31, 2007
  18. Theodore TsoJan 31, 2007
  19. Junio C HamanoJan 31, 2007
  20. Jakub NarebskiJan 31, 2007
  21. Nicolas PitreJan 31, 2007
  22. Daniel BarkalowJan 31, 2007
  23. Nicolas PitreJan 31, 2007
  24. Daniel BarkalowJan 31, 2007
  25. Nicolas PitreJan 31, 2007
  26. J. Bruce FieldsJan 31, 2007
  27. Jakub NarebskiJan 31, 2007
  28. Nicolas PitreJan 31, 2007
  29. Daniel BarkalowJan 31, 2007
  30. Nicolas PitreJan 31, 2007
  31. Guilhem BonnefilleJan 31, 2007
  32. Carl WorthJan 31, 2007
  33. Johannes SchindelinJan 31, 2007
  34. Santi BéjarJan 31, 2007
  35. Carl WorthJan 31, 2007
  36. Josef WeidendorferFeb 1, 2007
  37. Santi BéjarFeb 1, 2007
  38. Jakub NarebskiFeb 1, 2007
  39. Carl WorthFeb 6, 2007
  40. Junio C HamanoFeb 6, 2007
  41. Junio C HamanoFeb 6, 2007
  42. Jeff KingFeb 6, 2007
  43. Carl WorthFeb 6, 2007
  44. Junio C HamanoFeb 6, 2007
  45. Carl WorthFeb 6, 2007
  46. Jakub NarebskiFeb 6, 2007
  47. Jeff KingFeb 6, 2007
  48. Junio C HamanoFeb 6, 2007
  49. Jeff KingFeb 6, 2007
  50. Nicolas PitreFeb 6, 2007

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.