Subject: [PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]

From: "Arsh Srivastava via GitGitGadget" <[email-masked]>
Date: Tue, 10 Mar 2026 13:28:57 +0000

From: Arsh Srivastava <[email-masked]>

Add a new advice type ADVICE_STASH_BEFORE_CHECKOUT to guide users
when they attempt to switch branches with local modifications that
would be overwritten by the operation.

The advice suggests using "git checkout -m" to carry local changes
over to the new branch in a single step.

The advice can be silenced with:

  git config set advice.stashBeforeCheckout false

Changes:
- advice.h: add ADVICE_STASH_BEFORE_CHECKOUT enum value
- advice.c: add "stashBeforeCheckout" to advice_setting[] and implement
  advise_on_checkout_dirty_files() function
- Documentation/config/advice.adoc: document the new advice key

Signed-off-by: Arsh Srivastava <[email-masked]>
---
 advice.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/advice.c b/advice.c
index e1264f525c..ba290d3760 100644
--- a/advice.c
+++ b/advice.c
@@ -327,15 +327,8 @@ void advise_on_checkout_dirty_files(struct string_list *file_list)
 	fprintf(stderr, "\t%s\n", item->string);
 
     advise_if_enabled(ADVICE_STASH_BEFORE_CHECKOUT,
-		      _("You can save your local changes before switching by running:\n"
+		      _("To carry your local changes over to the new branch, use:\n"
 			"\n"
-			"\tgit stash push\n"
-			"\n"
-			"Then restore them after switching with:\n"
-			"\n"
-			"\tgit stash pop\n"
-			"\n"
-			"Or to discard your local changes, use:\n"
-			"\n"
-			"\tgit checkout -- <file>"));
+			"\tgit checkout -m <branch>\n"
+			));
 }
-- 
gitgitgadget