[PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
- From
Arsh Srivastava via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 10, 2026, 13:28 UTC
- Message-ID
- <e88c85170147a7c5d44640cba0c48aa686e23f17.1773149337.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.2233.v3.git.git.1773149337.gitgitgadget@gmail.com>
From: Arsh Srivastava <arshsrivastava00@gmail.com>
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 <arshsrivastava00@gmail.com> --- 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