Subject: [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions

From: "Arsh Srivastava via GitGitGadget" <[email-masked]>
Date: Wed, 11 Mar 2026 08:50:26 +0000

From: Arsh Srivastava <[email-masked]>

This comment is an extention to the already existing stash comment.

After the valuable insights given to me by git maintaniers.
I removed the new function I introduced.
Added updated comment over the already existing function
"setup_unpack_trees_porcelain" with "git checkout -m <branch>"
and its repercussions
I have also mentioned the repercussions of using "-m".

Signed-off-by: Arsh Srivastava <[email-masked]>
---
 Documentation/config/advice.adoc |  5 -----
 advice.c                         | 20 --------------------
 advice.h                         |  2 --
 unpack-trees.c                   | 13 +++++++++++--
 4 files changed, 11 insertions(+), 29 deletions(-)

diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 8752e05636..257db58918 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,11 +126,6 @@ all advice messages.
 		Shown when a sparse index is expanded to a full index, which is likely
 		due to an unexpected set of files existing outside of the
 		sparse-checkout.
-	stashBeforeCheckout::
-		Shown when the user attempts to switch branches but has
-		local modifications that would be overwritten by the
-		operation, to suggest using linkgit:git-stash[1] to
-		save changes before switching.
 	statusAheadBehind::
 		Shown when linkgit:git-status[1] computes the ahead/behind
 		counts for a local ref compared to its remote tracking ref,
diff --git a/advice.c b/advice.c
index ba290d3760..0018501b7b 100644
--- a/advice.c
+++ b/advice.c
@@ -81,7 +81,6 @@ static struct {
 	[ADVICE_SET_UPSTREAM_FAILURE]			= { "setUpstreamFailure" },
 	[ADVICE_SKIPPED_CHERRY_PICKS]			= { "skippedCherryPicks" },
 	[ADVICE_SPARSE_INDEX_EXPANDED]			= { "sparseIndexExpanded" },
-	[ADVICE_STASH_BEFORE_CHECKOUT] = { "stashBeforeCheckout" },
 	[ADVICE_STATUS_AHEAD_BEHIND_WARNING]		= { "statusAheadBehindWarning" },
 	[ADVICE_STATUS_HINTS]				= { "statusHints" },
 	[ADVICE_STATUS_U_OPTION]			= { "statusUoption" },
@@ -313,22 +312,3 @@ void advise_on_moving_dirty_path(struct string_list *pathspec_list)
 			    "* Use \"git add --sparse <paths>\" to update the index\n"
 			    "* Use \"git sparse-checkout reapply\" to apply the sparsity rules"));
 }
-
-void advise_on_checkout_dirty_files(struct string_list *file_list)
-{
-    struct string_list_item *item;
-
-    if (!file_list->nr)
-	return;
-
-    fprintf(stderr, _("The following files have local modifications that would\n"
-		      "be overwritten by switching branches:\n"));
-    for_each_string_list_item(item, file_list)
-	fprintf(stderr, "\t%s\n", item->string);
-
-    advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
-		      _("To carry your local changes over to the new branch, use:\n"
-			"\n"
-			"\tgit checkout -m <branch>\n"
-			));
-}
diff --git a/advice.h b/advice.h
index c035b5d8e3..8def280688 100644
--- a/advice.h
+++ b/advice.h
@@ -48,7 +48,6 @@ enum advice_type {
 	ADVICE_SET_UPSTREAM_FAILURE,
 	ADVICE_SKIPPED_CHERRY_PICKS,
 	ADVICE_SPARSE_INDEX_EXPANDED,
-	ADVICE_STASH_BEFORE_CHECKOUT,
 	ADVICE_STATUS_AHEAD_BEHIND_WARNING,
 	ADVICE_STATUS_HINTS,
 	ADVICE_STATUS_U_OPTION,
@@ -84,6 +83,5 @@ void NORETURN die_ff_impossible(void);
 void advise_on_updating_sparse_paths(struct string_list *pathspec_list);
 void detach_advice(const char *new_name);
 void advise_on_moving_dirty_path(struct string_list *pathspec_list);
-void advise_on_checkout_dirty_files(struct string_list *file_list);
 
 #endif /* ADVICE_H */
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..9449ee8203 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,17 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
 	if (!strcmp(cmd, "checkout"))
 		msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
 		      ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
-			  "Please commit your changes or stash them before you switch branches.")
-		      : _("Your local changes to the following files would be overwritten by checkout:\n%%s");
+			  "Please commit your changes or stash them before you switch branches.\n"
+			  "Try using 'git checkout -m <branch>' for a quick fix. \n"
+			  "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+			  "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+			  )
+		      : _("Your local changes to the following files would be overwritten by checkout:\n%%s"
+				"Please commit your changes or stash them before you switch branches.\n"
+			  "Try using 'git checkout -m <branch>' for a quick fix.\n"
+			  "Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.\n"
+			  "Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone."
+			  );
 	else if (!strcmp(cmd, "merge"))
 		msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
 		      ? _("Your local changes to the following files would be overwritten by merge:\n%%s"
-- 
gitgitgadget