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

[PATCH] git-checkout: disable guides how to switch branches with ui.guide

From
MLMatthias Lederhofer <matled@gmx.net>
Date
Feb 1, 2007, 18:44 UTC
Message-ID
<20070201184403.GA6326@moooo.ath.cx>
In-Reply-To
<7vlkjip7mu.fsf_-_@assigned-by-dhcp.cox.net>

--- Junio C Hamano <junkio@cox.net> wrote:

Show 22 quoted lines
> * Detaching head would say which commit I am at and reminds me that
>   I am not on any branch (not that I would detach my HEAD while keeping
>   precious local changes around in any real-world workflow -- this is
>   just a sample session).
> 
>     [git.git (master)]$ git checkout master^
>     M       git-checkout.sh
>     Note: you are not on any branch and are at commit "master^"
>     If you want to create a new branch from this checkout, you may do so
>     (now or later) by using -b with the checkout command again. Example:
>       git checkout -b <new_branch_name>
> 
> * Coming back to an attached state can lose the detached HEAD, so
>   I get warned and stopped.
> 
>     [git.git]$ git checkout master
>     You are not on any branch and switching to branch 'master'
>     may lose your changes.  At this point, you can do one of two things:
>      (1) Decide it is Ok and say 'git checkout -f master';
>      (2) Start a new branch from the current commit, by saying
>          'git checkout -b <branch-name>'.
>     Leaving your HEAD detached; not switching to branch 'master'.

I think these two are too long, after a few times one knows exactly what to do and all this text is not necessary anymore.

Perhaps the name (ui.guide) should be different, I just did not find
any category to put this in.  The variable could become a general
variable to enable/disable very verbose explanations what to do in a
situation.
---
 git-checkout.sh |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/git-checkout.sh b/git-checkout.sh
index deb4795..1eb8b06 100755
--- a/git-checkout.sh
+++ b/git-checkout.sh
@@ -5,6 +5,8 @@ SUBDIRECTORY_OK=Sometimes
 . git-sh-setup
 require_work_tree
 
+guide=$(git repo-config --bool --get ui.guide)
+[ -z "$guide" ] && guide=true
 old_name=HEAD
 old=$(git-rev-parse --verify $old_name 2>/dev/null)
 oldbranch=$(git-symbolic-ref $old_name 2>/dev/null)
@@ -155,10 +157,13 @@ then
 	detached="$new"
 	if test -n "$oldbranch"
 	then
-		detach_warn="Note: you are not on any branch and are at commit \"$new_name\"
+		detach_warn="Note: you are not on any branch and are at commit \"$new_name\""
+		if test "$guide" = true; then
+			detach_warn="$detach_warn
 If you want to create a new branch from this checkout, you may do so
 (now or later) by using -b with the checkout command again. Example:
   git checkout -b <new_branch_name>"
+		fi
 	fi
 elif test -z "$oldbranch" && test -n "$branch"
 then
@@ -166,13 +171,18 @@ then
 	if test -z "$force"
 	then
 		git show-ref -d -s | grep "$old" >/dev/null || {
-			echo >&2 \
+			if test "$guide" = true; then
+				echo >&2 \
 "You are not on any branch and switching to branch '$new_name'
 may lose your changes.  At this point, you can do one of two things:
  (1) Decide it is Ok and say 'git checkout -f $new_name';
  (2) Start a new branch from the current commit, by saying
      'git checkout -b <branch-name>'.
 Leaving your HEAD detached; not switching to branch '$new_name'."
+			else
+				echo >&2 \
+"HEAD detached; use -f to switch to branch '$new_name'."
+			fi
 			exit 1;
 		}
 	fi
-- 
1.5.0.rc3.g4a88
Previous: Alex RiesenNext: Junio C Hamano
Message 20 of 35 in “tone down the detached head warning”
  1. tone down the detached head warningNicolas Pitre, Jan 31, 2007
  2. Jeff KingJan 31, 2007
  3. Jakub NarebskiJan 31, 2007
  4. Jeff KingJan 31, 2007
  5. Jakub NarebskiJan 31, 2007
  6. Carl WorthJan 31, 2007
  7. Jakub NarebskiFeb 1, 2007
  8. Andy ParkinsFeb 1, 2007
  9. Matthias LederhoferFeb 1, 2007
  10. Nicolas PitreFeb 1, 2007
  11. Jeff KingFeb 1, 2007
  12. Junio C HamanoFeb 1, 2007
  13. Jeff KingFeb 1, 2007
  14. Nicolas PitreFeb 1, 2007
  15. Jeff KingFeb 1, 2007
  16. detached HEAD -- finishing touchesJunio C Hamano, Feb 1, 2007
  17. Raimund BauerFeb 1, 2007
  18. Alex RiesenFeb 1, 2007
  19. Alex RiesenFeb 1, 2007
  20. git-checkout: disable guides how to switch branches with ui.guideMatthias Lederhofer, Feb 1, 2007
  21. Junio C HamanoFeb 1, 2007
  22. Matthias LederhoferFeb 1, 2007
  23. Junio C HamanoFeb 1, 2007
  24. Matthias LederhoferFeb 1, 2007
  25. Carl WorthFeb 1, 2007
  26. Nicolas PitreFeb 1, 2007
  27. Carl WorthFeb 1, 2007
  28. Jakub NarebskiFeb 1, 2007
  29. Theodore TsoFeb 1, 2007
  30. Junio C HamanoFeb 2, 2007
  31. Theodore TsoFeb 2, 2007
  32. Carl WorthFeb 2, 2007
  33. Junio C HamanoFeb 2, 2007
  34. Carl WorthFeb 2, 2007
  35. Junio C HamanoFeb 2, 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.