From: Arsh Srivastava via GitGitGadget Date: Wed, 11 Mar 2026 08:50:25 GMT Subject: [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Message-ID: In-Reply-To: From: Arsh Srivastava 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 --- 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 -- ")); + "\tgit checkout -m \n" + )); } -- gitgitgadget