* [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
` (5 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
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.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ 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 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ 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" },
@@ -312,3 +313,29 @@ 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,
+ _("You can save your local changes before switching by running:\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>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ 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,
@@ -83,5 +84,6 @@ 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 */
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
` (4 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
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
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 1/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 2/5] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC] Arsh Srivastava via GitGitGadget
` (3 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
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 <arshsrivastava00@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC]
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (2 preceding siblings ...)
2026-03-11 8:50 ` [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 8:50 ` [PATCH v4 5/5] File updation [GSOC] Arsh Srivastava via GitGitGadget
` (2 subsequent siblings)
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
While submitting my previous commit found that
previous testcases weren't working properly
with my updates
So fixed the test updates and advice conflict issue.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
t/t6439-merge-co-error-msgs.sh | 4 ++++
t/t7406-submodule-update.sh | 2 ++
unpack-trees.c | 6 +-----
3 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..6ebc1d2565 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -77,6 +77,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -99,6 +101,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..a359429bf5 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -212,6 +212,8 @@ test_expect_success 'submodule update should fail due to local changes' '
> error: Your local changes to the following files would be overwritten by checkout:
> file
> Please commit your changes or stash them before you switch branches.
+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 9449ee8203..cb4cdee9b9 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -134,11 +134,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
"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."
- );
+ "Please commit your changes or stash them before you switch branches.");
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
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v4 5/5] File updation [GSOC]
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (3 preceding siblings ...)
2026-03-11 8:50 ` [PATCH v4 4/5] Updating tests and unpack-tress.c [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 8:50 ` Arsh Srivastava via GitGitGadget
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
6 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 8:50 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
I have ran tests locally for this file
and tried to fix all the CI issues
Lets Hope it works
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
t/t6439-merge-co-error-msgs.sh | 6 ++++--
t/t7406-submodule-update.sh | 3 ++-
unpack-trees.c | 2 +-
3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 6ebc1d2565..cf996e0e51 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -78,7 +78,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/two
Please commit your changes or stash them before you switch branches.
Try using 'git checkout -m <branch>' for a quick fix.
-Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -102,7 +103,8 @@ error: Your local changes to the following files would be overwritten by checkou
rep/two
Please commit your changes or stash them before you switch branches.
Try using 'git checkout -m <branch>' for a quick fix.
-Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index a359429bf5..2e4cc9b3fe 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -213,7 +213,8 @@ test_expect_success 'submodule update should fail due to local changes' '
> file
> Please commit your changes or stash them before you switch branches.
> Try using '\''git checkout -m <branch>'\'' for a quick fix.
- > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them. Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index cb4cdee9b9..9835a82455 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -129,7 +129,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
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.\n"
- "Try using 'git checkout -m <branch>' for a quick fix. \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."
)
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v4 0/5] Advice on checkout dirty files
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (4 preceding siblings ...)
2026-03-11 8:50 ` [PATCH v4 5/5] File updation [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 16:38 ` Junio C Hamano
2026-03-11 17:06 ` Arsh Srivastava
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
6 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-11 16:38 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> This is my submission for microproject [GSOC]
>
> This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
> when they attempt to switch branches with local modifications that would be
> overwritten by the operation.
>
> The new advice follows the same patterns established by existing advice
> functions such as advise_on_updating_sparse_paths(). When triggered, it
> lists the affected files and suggests using git stash push/pop to save and
> restore local changes.
>
> 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
Even though no developer is perfect, when you are presenting your
updated work, armed with wisdom borrowed from your reviewers'
comments on your earlier attempts, you are expected to take the
opportunity to pretend to have written a series of patches that are
perfect logical progression towards the final shape of the code
without detours, change of plans, and fixing earlier mistakes made
in the series.
Please do not throw a drunken-man's-walk series at us. For example,
I see that [PATCH 3/5] literally removes what was added by earlier
patches. This is not a place for you to show how you made wrong
turns before arriving at the final shape of the code.
The final series accepted by the project will have to stay in our
history for later developers to see in "git log" output to learn
from, and a series being clean logical progression is a must for
that to happen.
Also, what is "updation"? Is it a standard English word, or some
dialect of an LLM origin?
> Arsh Srivastava (5):
> advice: add stashBeforeCheckout advice for dirty branch switches
> advice: add stashBeforeCheckout advice for dirty branch switches
> [GSOC]
> unpack-trees: suggesting 'git checkout -m <branch>' with its
> repercussions
> Updating tests and unpack-tress.c [GSOC]
> File updation [GSOC]
>
> t/t6439-merge-co-error-msgs.sh | 6 ++++++
> t/t7406-submodule-update.sh | 3 +++
> unpack-trees.c | 9 +++++++--
> 3 files changed, 16 insertions(+), 2 deletions(-)
>
>
> base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
> Pull-Request: https://github.com/git/git/pull/2233
>
> Range-diff vs v3:
>
> 1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
> 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
> -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
> -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC]
> -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
^ permalink raw reply [flat|nested] 62+ messages in thread* Re: [PATCH v4 0/5] Advice on checkout dirty files
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
@ 2026-03-11 17:06 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-11 17:06 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :-
> provide perfect logic not drunken-man's-walk series.
> not a place for you to show how you made wrong turns before arriving at the final shape of the code.
> history for later developers to see in "git log" output to learn from
> what is "updation"
Thank you so much for your feedback.
Again terribly sorry I will rebase my commit so that it has perfect progression.
And updation is a noun first published in Oxford English Dictionary in 2018.
On Wed, 11 Mar 2026 at 22:08, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > This is my submission for microproject [GSOC]
> >
> > This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
> > when they attempt to switch branches with local modifications that would be
> > overwritten by the operation.
> >
> > The new advice follows the same patterns established by existing advice
> > functions such as advise_on_updating_sparse_paths(). When triggered, it
> > lists the affected files and suggests using git stash push/pop to save and
> > restore local changes.
> >
> > 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
>
> Even though no developer is perfect, when you are presenting your
> updated work, armed with wisdom borrowed from your reviewers'
> comments on your earlier attempts, you are expected to take the
> opportunity to pretend to have written a series of patches that are
> perfect logical progression towards the final shape of the code
> without detours, change of plans, and fixing earlier mistakes made
> in the series.
>
> Please do not throw a drunken-man's-walk series at us. For example,
> I see that [PATCH 3/5] literally removes what was added by earlier
> patches. This is not a place for you to show how you made wrong
> turns before arriving at the final shape of the code.
>
> The final series accepted by the project will have to stay in our
> history for later developers to see in "git log" output to learn
> from, and a series being clean logical progression is a must for
> that to happen.
>
> Also, what is "updation"? Is it a standard English word, or some
> dialect of an LLM origin?
>
> > Arsh Srivastava (5):
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > [GSOC]
> > unpack-trees: suggesting 'git checkout -m <branch>' with its
> > repercussions
> > Updating tests and unpack-tress.c [GSOC]
> > File updation [GSOC]
> >
> > t/t6439-merge-co-error-msgs.sh | 6 ++++++
> > t/t7406-submodule-update.sh | 3 +++
> > unpack-trees.c | 9 +++++++--
> > 3 files changed, 16 insertions(+), 2 deletions(-)
> >
> >
> > base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
> > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v4
> > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v4
> > Pull-Request: https://github.com/git/git/pull/2233
> >
> > Range-diff vs v3:
> >
> > 1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
> > 2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
> > -: ---------- > 3: 4237b9667d unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
> > -: ---------- > 4: b25ea22410 Updating tests and unpack-tress.c [GSOC]
> > -: ---------- > 5: 2ef7d5a3d6 File updation [GSOC]
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v5 0/3] Advice on checkout dirty files
2026-03-11 8:50 ` [PATCH v4 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
` (5 preceding siblings ...)
2026-03-11 16:38 ` [PATCH v4 0/5] Advice on checkout dirty files Junio C Hamano
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
` (4 more replies)
6 siblings, 5 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava
This is my submission for microproject [GSOC]
This patch adds a new advice type ADVICE_STASH_BEFORE_CHECKOUT to help users
when they attempt to switch branches with local modifications that would be
overwritten by the operation.
The new advice follows the same patterns established by existing advice
functions such as advise_on_updating_sparse_paths(). When triggered, it
lists the affected files and suggests using git stash push/pop to save and
restore local changes.
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
Arsh Srivastava (3):
advice: add stashBeforeCheckout advice for dirty branch switches
advice: add stashBeforeCheckout advice for dirty branch switches
[GSOC]
unpack-trees: suggesting 'git checkout -m <branch>' with its
repercussions
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
3 files changed, 16 insertions(+), 2 deletions(-)
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v5
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v5
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v4:
1: eb5639dbc3 = 1: eb5639dbc3 advice: add stashBeforeCheckout advice for dirty branch switches
2: e88c851701 = 2: e88c851701 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
3: 4237b9667d ! 3: 1cc22f437e unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
@@ advice.h: void NORETURN die_ff_impossible(void);
#endif /* ADVICE_H */
+ ## t/t6439-merge-co-error-msgs.sh ##
+@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+ rep/one
+ rep/two
+ Please commit your changes or stash them before you switch branches.
++Try using 'git checkout -m <branch>' for a quick fix.
++Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ Aborting
+ EOF
+
+@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+ rep/one
+ rep/two
+ Please commit your changes or stash them before you switch branches.
++Try using 'git checkout -m <branch>' for a quick fix.
++Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ Aborting
+ EOF
+
+
+ ## t/t7406-submodule-update.sh ##
+@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update should fail due to local changes' '
+ > error: Your local changes to the following files would be overwritten by checkout:
+ > file
+ > Please commit your changes or stash them before you switch branches.
++ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
++ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
++ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+ > Aborting
+ > fatal: Unable to checkout OID in submodule path '\''submodule'\''
+ EOF
+
## unpack-trees.c ##
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *opts,
if (!strcmp(cmd, "checkout"))
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *o
- "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"
++ "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."
-+ );
++ "Please commit your changes or stash them before you switch branches.");
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"
4: b25ea22410 < -: ---------- Updating tests and unpack-tress.c [GSOC]
5: 2ef7d5a3d6 < -: ---------- File updation [GSOC]
--
gitgitgadget
^ permalink raw reply [flat|nested] 62+ messages in thread* [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
` (3 subsequent siblings)
4 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
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.
This includes:
> New ADVICE_STASH_BEFORE_CHECKOUT enum value in advice.h
> Corresponding "stashBeforeCheckout" entry in advice_setting[]
> New advise_on_checkout_dirty_files() function that lists the
affected files and suggests using git stash push/pop
> Documentation entry in Documentation/config/advice.txt
The advice follows existing patterns established by
advise_on_updating_sparse_paths() and can be silenced with:
git config set advice.stashBeforeCheckout false
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 +++++
advice.c | 27 +++++++++++++++++++++++++++
advice.h | 2 ++
3 files changed, 34 insertions(+)
diff --git a/Documentation/config/advice.adoc b/Documentation/config/advice.adoc
index 257db58918..8752e05636 100644
--- a/Documentation/config/advice.adoc
+++ b/Documentation/config/advice.adoc
@@ -126,6 +126,11 @@ 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 0018501b7b..e1264f525c 100644
--- a/advice.c
+++ b/advice.c
@@ -81,6 +81,7 @@ 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" },
@@ -312,3 +313,29 @@ 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,
+ _("You can save your local changes before switching by running:\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>"));
+}
diff --git a/advice.h b/advice.h
index 8def280688..c035b5d8e3 100644
--- a/advice.h
+++ b/advice.h
@@ -48,6 +48,7 @@ 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,
@@ -83,5 +84,6 @@ 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 */
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
` (2 subsequent siblings)
4 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
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
^ permalink raw reply related [flat|nested] 62+ messages in thread* [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 1/3] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-11 17:49 ` [PATCH v5 2/3] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
@ 2026-03-11 17:49 ` Arsh Srivastava via GitGitGadget
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
4 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-11 17:49 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
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 <arshsrivastava00@gmail.com>
---
Documentation/config/advice.adoc | 5 -----
advice.c | 20 --------------------
advice.h | 2 --
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
6 files changed, 16 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/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..cf996e0e51 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..2e4cc9b3fe 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' '
> error: Your local changes to the following files would be overwritten by checkout:
> file
> Please commit your changes or stash them before you switch branches.
+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..9835a82455 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,13 @@ 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.");
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
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v5 0/3] Advice on checkout dirty files
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
` (2 preceding siblings ...)
2026-03-11 17:49 ` [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
@ 2026-03-12 1:02 ` Junio C Hamano
2026-03-12 3:32 ` Arsh Srivastava
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
4 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 1:02 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> 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
>
> Arsh Srivastava (3):
> advice: add stashBeforeCheckout advice for dirty branch switches
> advice: add stashBeforeCheckout advice for dirty branch switches
> [GSOC]
> unpack-trees: suggesting 'git checkout -m <branch>' with its
> repercussions
I still see that [PATCH 3/3] literally removes what was added by
earlier patches. ADVICE_STASH_BEFORE_CHECKOUT is added to
advice.[ch] and stashBeforeCheckOut is added to
Documentation/config/adivce.adoc in [1/3], and then they are removed
in [3/3]. If your final solution does not involve such an advice,
then do not even add it in an earlier patch, only to retract it and
replace it with something else in a later patch. If the reason why
that "something else" replaces the advice is because it is a better
solution to the problem you initially started to solve than the
advice message added in [1/3], then just go straight to that
"something else", without adding and removing the advice mechanism.
That is what "perfect logical progression without detours, change of
plans, and fixes earlier mistake" is about.
In other words, please do not throw a drunken-man's-walk series at
us. Pretend to be a perfect developer.
The final series accepted by the project will have to stay in our
history for later developers to see in "git log" output to learn
from, and a series being clean logical progression is a must for
that to happen.
^ permalink raw reply [flat|nested] 62+ messages in thread* Re: [PATCH v5 0/3] Advice on checkout dirty files
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
@ 2026-03-12 3:32 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 3:32 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :
> He still see 3 patches for a work that can be done by one.
> That is what "perfect logical progression without detours, change of
> plans, and fixes earlier mistake" is about.
> please do not throw a drunken-man's-walk series at
> us. Pretend to be a perfect developer
I understand now sorry for the inconvenience.
Your mail also specified the same thing but I was not able to truly
grasp the essence of that mail.
Thank you for explaining it again to me, I now have clear
understanding of what is expected from me.
I will create one single commit :) .
I also saw that git via git gadget forwards all my commits making it
messy and not ideal.
I will make a clean single commit that will look perfect and wouldn't
make such a messy commit history.
On Thu, 12 Mar 2026 at 06:32, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > 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
> >
> > Arsh Srivastava (3):
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > advice: add stashBeforeCheckout advice for dirty branch switches
> > [GSOC]
> > unpack-trees: suggesting 'git checkout -m <branch>' with its
> > repercussions
>
> I still see that [PATCH 3/3] literally removes what was added by
> earlier patches. ADVICE_STASH_BEFORE_CHECKOUT is added to
> advice.[ch] and stashBeforeCheckOut is added to
> Documentation/config/adivce.adoc in [1/3], and then they are removed
> in [3/3]. If your final solution does not involve such an advice,
> then do not even add it in an earlier patch, only to retract it and
> replace it with something else in a later patch. If the reason why
> that "something else" replaces the advice is because it is a better
> solution to the problem you initially started to solve than the
> advice message added in [1/3], then just go straight to that
> "something else", without adding and removing the advice mechanism.
>
> That is what "perfect logical progression without detours, change of
> plans, and fixes earlier mistake" is about.
>
> In other words, please do not throw a drunken-man's-walk series at
> us. Pretend to be a perfect developer.
>
> The final series accepted by the project will have to stay in our
> history for later developers to see in "git log" output to learn
> from, and a series being clean logical progression is a must for
> that to happen.
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-11 17:49 ` [PATCH v5 0/3] " Arsh Srivastava via GitGitGadget
` (3 preceding siblings ...)
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files Junio C Hamano
@ 2026-03-12 4:00 ` Arsh Srivastava via GitGitGadget
2026-03-12 16:06 ` Junio C Hamano
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
4 siblings, 2 replies; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-12 4:00 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
This comment is an extention to the already existing stash comment.
Added updated comment over the already existing function
"setup_unpack_trees_porcelain" with "git checkout -m"
and its repercussions
I have also mentioned the repercussions of using "-m".
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch extends the current message to help users better understand
risks and alternatives to stashing their changes.
The alternative consists of
> git checkout -m and its repercussions.
This extended message is tied to the existing advice.commitBeforeMerge
configuration and can be silenced with:
> git config set advice.commitBeforeMerge false
Changes:
> unpack-trees.c: expanded the already existing message.
> t/t6439-merge-co-error-msgs.sh: update expected output for merge and
> checkout tests. t/t7406-submodule-update.sh: update expected output
> for submodule checkout tests.
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v6
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v6
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v5:
1: eb5639dbc3 < -: ---------- advice: add stashBeforeCheckout advice for dirty branch switches
2: e88c851701 < -: ---------- advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]
3: 1cc22f437e ! 1: e0ba5fad82 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
@@ Metadata
Author: Arsh Srivastava <arshsrivastava00@gmail.com>
## Commit message ##
- unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
+ unpack-trees: suggesting 'git checkout -m' with its repercussions
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>"
+ "setup_unpack_trees_porcelain" with "git checkout -m"
and its repercussions
I have also mentioned the repercussions of using "-m".
- Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
-
- ## Documentation/config/advice.adoc ##
-@@ Documentation/config/advice.adoc: 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,
-
- ## advice.c ##
-@@ advice.c: 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" },
-@@ advice.c: 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"
-- ));
--}
-
- ## advice.h ##
-@@ advice.h: 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,
-@@ advice.h: 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 */
+ Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
## t/t6439-merge-co-error-msgs.sh ##
@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
t/t6439-merge-co-error-msgs.sh | 6 ++++++
t/t7406-submodule-update.sh | 3 +++
unpack-trees.c | 9 +++++++--
3 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..cf996e0e51 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -77,6 +77,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
@@ -99,6 +102,9 @@ error: Your local changes to the following files would be overwritten by checkou
rep/one
rep/two
Please commit your changes or stash them before you switch branches.
+Try using 'git checkout -m <branch>' for a quick fix.
+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..2e4cc9b3fe 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -212,6 +212,9 @@ test_expect_success 'submodule update should fail due to local changes' '
> error: Your local changes to the following files would be overwritten by checkout:
> file
> Please commit your changes or stash them before you switch branches.
+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..9835a82455 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,13 @@ 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.");
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"
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
@ 2026-03-12 16:06 ` Junio C Hamano
2026-03-12 18:13 ` Arsh Srivastava
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
1 sibling, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 16:06 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> From: Arsh Srivastava <arshsrivastava00@gmail.com>
>
> This comment is an extention to the already existing stash comment.
> Added updated comment over the already existing function
> "setup_unpack_trees_porcelain" with "git checkout -m"
> and its repercussions
> I have also mentioned the repercussions of using "-m".
>
> Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
The commit message should focus on the "why" and "what" from a user
perspective, following the project's standard format (problem
description, then solution).
Consider a more standard phrasing:
unpack-trees: suggest 'git checkout -m' when checkout fails
When a branch switch fails due to local changes, we suggest
stashing or committing. However, 'git checkout -m' is a valid
alternative for users who wish to carry their changes over via a
merge.
Update the advice message to suggest this option, while
including a warning about the potential for data loss if a hard
reset is performed after a conflicted merge.
Also, note that "extention" is a typo; it should be "extension".
Having said that, I am not sure if we want to suggest "checkout -m"
in this situation after all.
The added message is quite long:
> Try using 'git checkout -m <branch>' for a quick fix.
> Please Note :- that using -m (merge) will not save your changes,
> rather would directly merge them.
> Meaning if you are not able to resolve conflicts and does --hard
> reset your local changes would be gone.
When advice requires a multi-line warning about potential data loss,
it's often a sign that the operation being suggested isn't suitable
for general advice. The goal of these messages should be to provide
a clear, safe next step, not a list of advanced alternatives with
caveats. After all, the users who need such an "it failed, now what
should I do to recover?" message the most are relatively
inexperienced users and we do not want the advice to be
overwhelming.
The primary concern is that 'git checkout -m' is a high-stakes
operation compared to 'git stash'.
- When a user uses 'git stash', their changes are recorded in a
stash entry. If 'git stash pop' later results in conflicts they
cannot resolve, the user can always 'git reset --hard' to get back
to a clean state, knowing their original changes are still safe in
the stash entry, which they can re-attempt to use later.
- In contrast, 'git checkout -m' performs the merge directly in
the working tree. If conflicts arise, the original local changes
are immediately replaced by conflict markers. Unlike stash, there
is no "undo" record. If the user realizes they are in over their
head, they cannot simply "abort" to get their original changes
back. They have only one chance to resolve it correctly, and they
have to do so right there.
Suggesting this "one-shot" approach to a user who is already in a
state of friction (and likely less experienced) might be providing
them with a "foot-gun" rather than a helpful tip. Generally, advice
that nudges users toward the safest "golden paths" like stashing or
committing is preferred.
For a microproject, you've successfully demonstrated that you can
modify the advice system and update the test suite. However, for the
health of the project's usability, it might be better to drop the
'checkout -m' suggestion and instead focus on making the existing
'stash' and 'commit' advice as clear and helpful as possible.
Thanks.
^ permalink raw reply [flat|nested] 62+ messages in thread* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 16:06 ` Junio C Hamano
@ 2026-03-12 18:13 ` Arsh Srivastava
2026-03-12 18:56 ` Junio C Hamano
0 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 18:13 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :
> The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
> Also showed an example for the same.
> Also, note that "extention" is a typo; it should be "extension".
> Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
> Pointed out the difference between "stash" and "checkout -m".
> When advice requires a multi-line warning about potential data loss.
> The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
> After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
> Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
> For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
> it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
Thank you so much for the valuable feedback.
I will redefine my advice and will make it more precise and will
change it to git stash which is truly more beneficial for the new
users.
Also will update my commit so that it is properly structured with
format first "why" then "what".
I will create a v7 with all these changes.
I am really obliged.
Thanks again for the guidance.
On Thu, 12 Mar 2026 at 21:36, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > From: Arsh Srivastava <arshsrivastava00@gmail.com>
> >
> > This comment is an extention to the already existing stash comment.
> > Added updated comment over the already existing function
> > "setup_unpack_trees_porcelain" with "git checkout -m"
> > and its repercussions
> > I have also mentioned the repercussions of using "-m".
> >
> > Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
>
> The commit message should focus on the "why" and "what" from a user
> perspective, following the project's standard format (problem
> description, then solution).
>
> Consider a more standard phrasing:
>
> unpack-trees: suggest 'git checkout -m' when checkout fails
>
> When a branch switch fails due to local changes, we suggest
> stashing or committing. However, 'git checkout -m' is a valid
> alternative for users who wish to carry their changes over via a
> merge.
>
> Update the advice message to suggest this option, while
> including a warning about the potential for data loss if a hard
> reset is performed after a conflicted merge.
>
> Also, note that "extention" is a typo; it should be "extension".
>
> Having said that, I am not sure if we want to suggest "checkout -m"
> in this situation after all.
>
> The added message is quite long:
>
> > Try using 'git checkout -m <branch>' for a quick fix.
> > Please Note :- that using -m (merge) will not save your changes,
> > rather would directly merge them.
> > Meaning if you are not able to resolve conflicts and does --hard
> > reset your local changes would be gone.
>
> When advice requires a multi-line warning about potential data loss,
> it's often a sign that the operation being suggested isn't suitable
> for general advice. The goal of these messages should be to provide
> a clear, safe next step, not a list of advanced alternatives with
> caveats. After all, the users who need such an "it failed, now what
> should I do to recover?" message the most are relatively
> inexperienced users and we do not want the advice to be
> overwhelming.
>
> The primary concern is that 'git checkout -m' is a high-stakes
> operation compared to 'git stash'.
>
> - When a user uses 'git stash', their changes are recorded in a
> stash entry. If 'git stash pop' later results in conflicts they
> cannot resolve, the user can always 'git reset --hard' to get back
> to a clean state, knowing their original changes are still safe in
> the stash entry, which they can re-attempt to use later.
>
> - In contrast, 'git checkout -m' performs the merge directly in
> the working tree. If conflicts arise, the original local changes
> are immediately replaced by conflict markers. Unlike stash, there
> is no "undo" record. If the user realizes they are in over their
> head, they cannot simply "abort" to get their original changes
> back. They have only one chance to resolve it correctly, and they
> have to do so right there.
>
> Suggesting this "one-shot" approach to a user who is already in a
> state of friction (and likely less experienced) might be providing
> them with a "foot-gun" rather than a helpful tip. Generally, advice
> that nudges users toward the safest "golden paths" like stashing or
> committing is preferred.
>
> For a microproject, you've successfully demonstrated that you can
> modify the advice system and update the test suite. However, for the
> health of the project's usability, it might be better to drop the
> 'checkout -m' suggestion and instead focus on making the existing
> 'stash' and 'commit' advice as clear and helpful as possible.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 18:13 ` Arsh Srivastava
@ 2026-03-12 18:56 ` Junio C Hamano
2026-03-12 19:03 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 18:56 UTC (permalink / raw)
To: Arsh Srivastava
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> writes :
>> The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
>> Also showed an example for the same.
>> Also, note that "extention" is a typo; it should be "extension".
>> Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
>> Pointed out the difference between "stash" and "checkout -m".
>> When advice requires a multi-line warning about potential data loss.
>> The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
>> After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
>> Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
>> For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
>> it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
I wonder where this came from, as it is quite unusual to have a
rephrased summary of what you respond to. Is this LLM-generated
summary that was copied-and-pasted without much human brain effort?
What is more usual is to quote the message you are responding to,
trim the parts you are not going to comment on and not necessary for
bystanders to read in order to understand your response, and then
sprinkle your comments in between the parts of the quoted message,
instead of saying only your thing before the message you are
responding to without trimming (which is highly frowned upon, and
people often tell you not to "top-post").
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 18:56 ` Junio C Hamano
@ 2026-03-12 19:03 ` Arsh Srivastava
2026-03-12 19:07 ` Junio C Hamano
0 siblings, 1 reply; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 19:03 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> write:
> I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to.
> Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
> What is more usual is to quote the message you are responding to.
Actually as suspicious as it looks the mail was written by me only and
I thought that each line was as important as other and
I wanted to reply to each point you mentioned
Sorry for shortening your response
next time I will make sure that I will make quotations direct.
On Fri, 13 Mar 2026 at 00:26, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Junio C Hamano <gitster@pobox.com> writes :
> >> The commit message should focus on the "why" and "what" from a user perspective, following the project's standard format (problem description, then solution).
> >> Also showed an example for the same.
> >> Also, note that "extention" is a typo; it should be "extension".
> >> Having said that, I am not sure if we want to suggest "checkout -m" in this situation after all.
> >> Pointed out the difference between "stash" and "checkout -m".
> >> When advice requires a multi-line warning about potential data loss.
> >> The goal of these messages should be to provide a clear, safe next step, not a list of advanced alternatives with caveats.
> >> After all, the users who need such an "it failed, now what should I do to recover?" message the most are relatively inexperienced users and we do not want the advice to be overwhelming.
> >> Suggesting this "one-shot" approach to a user who is already in a state of friction (and likely less experienced) might be providing them with a "foot-gun" rather than a helpful tip. Generally, advice that nudges users toward the safest "golden paths" like stashing or committing is preferred.
> >> For a microproject, you've successfully demonstrated that you can modify the advice system and update the test suite.
> >> it might be better to drop the 'checkout -m' suggestion and instead focus on making the existing 'stash' and 'commit' advice as clear and helpful as possible.
>
> I wonder where this came from, as it is quite unusual to have a
> rephrased summary of what you respond to. Is this LLM-generated
> summary that was copied-and-pasted without much human brain effort?
>
> What is more usual is to quote the message you are responding to,
> trim the parts you are not going to comment on and not necessary for
> bystanders to read in order to understand your response, and then
> sprinkle your comments in between the parts of the quoted message,
> instead of saying only your thing before the message you are
> responding to without trimming (which is highly frowned upon, and
> people often tell you not to "top-post").
>
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 19:03 ` Arsh Srivastava
@ 2026-03-12 19:07 ` Junio C Hamano
2026-03-12 19:12 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 19:07 UTC (permalink / raw)
To: Arsh Srivastava
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> write:
>> I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to.
>> Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
>> What is more usual is to quote the message you are responding to.
>
> Actually as suspicious as it looks the mail was written by me only and
> I thought that each line was as important as other and
> I wanted to reply to each point you mentioned
> Sorry for shortening your response
> next time I will make sure that I will make quotations direct.
That wasn't what I meant, and you are still top-posting X-<.
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions
2026-03-12 19:07 ` Junio C Hamano
@ 2026-03-12 19:12 ` Arsh Srivastava
0 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-12 19:12 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> write:
> That wasn't what I meant, and you are still top-posting X-<.
Oh.. I understand now I mistakenly again used top-posting mail (-<
which is frustrating
I will use the recommended method only from now on. : )
On Fri, 13 Mar 2026 at 00:37, Junio C Hamano <gitster@pobox.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Junio C Hamano <gitster@pobox.com> write:
> >> I wonder where this came from, as it is quite unusual to have a rephrased summary of what you respond to.
> >> Is this LLM-generated summary that was copied-and-pasted without much human brain effort?
> >> What is more usual is to quote the message you are responding to.
> >
> > Actually as suspicious as it looks the mail was written by me only and
> > I thought that each line was as important as other and
> > I wanted to reply to each point you mentioned
> > Sorry for shortening your response
> > next time I will make sure that I will make quotations direct.
>
> That wasn't what I meant, and you are still top-posting X-<.
^ permalink raw reply [flat|nested] 62+ messages in thread
* [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-12 4:00 ` [PATCH v6] unpack-trees: suggesting 'git checkout -m' with its repercussions Arsh Srivastava via GitGitGadget
2026-03-12 16:06 ` Junio C Hamano
@ 2026-03-12 20:05 ` Arsh Srivastava via GitGitGadget
2026-03-12 22:40 ` Junio C Hamano
1 sibling, 1 reply; 62+ messages in thread
From: Arsh Srivastava via GitGitGadget @ 2026-03-12 20:05 UTC (permalink / raw)
To: git
Cc: Phillip Wood, Arsh Srivastava, Patrick Steinhardt, Karthik Nayak,
Arsh Srivastava, Arsh Srivastava
From: Arsh Srivastava <arshsrivastava00@gmail.com>
When a branch switch fails due to local changes and
new users who are not familiar with the error message often
get confused about how to move ahead and resolve the issue as
the previous error message only suggests to commit or stash the changes
but doesn't explain how to do that or what the next steps are.
This patch enhances the error message with more specific
instructions in a concise manner to help users understand
how to resolve the issue and move their local changes
safely to the other branch using stash.
Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
---
Advice on checkout dirty files
This is my submission for microproject [GSOC]
This patch extends the current message to help users better understand
risks and alternatives to stashing their changes.
The alternative consists of
> git checkout -m and its repercussions.
This extended message is tied to the existing advice.commitBeforeMerge
configuration and can be silenced with:
> git config set advice.commitBeforeMerge false
Changes:
> unpack-trees.c: expanded the already existing message.
> t/t6439-merge-co-error-msgs.sh: update expected output for merge and
> checkout tests. t/t7406-submodule-update.sh: update expected output
> for submodule checkout tests.
Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2233%2FArsh123344423%2Fadvice_on_checkout_dirty_files-v7
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2233/Arsh123344423/advice_on_checkout_dirty_files-v7
Pull-Request: https://github.com/git/git/pull/2233
Range-diff vs v6:
1: e0ba5fad82 ! 1: 72cb550621 unpack-trees: suggesting 'git checkout -m' with its repercussions
@@ Metadata
Author: Arsh Srivastava <arshsrivastava00@gmail.com>
## Commit message ##
- unpack-trees: suggesting 'git checkout -m' with its repercussions
+ unpack-trees: suggest using 'git stash' when checkout fails
- This comment is an extention to the already existing stash comment.
- Added updated comment over the already existing function
- "setup_unpack_trees_porcelain" with "git checkout -m"
- and its repercussions
- I have also mentioned the repercussions of using "-m".
+ When a branch switch fails due to local changes and
+ new users who are not familiar with the error message often
+ get confused about how to move ahead and resolve the issue as
+ the previous error message only suggests to commit or stash the changes
+ but doesn't explain how to do that or what the next steps are.
- Signed-off-by: Arsh Srivastava arshsrivastava00@gmail.com
+ This patch enhances the error message with more specific
+ instructions in a concise manner to help users understand
+ how to resolve the issue and move their local changes
+ safely to the other branch using stash.
+
+ Signed-off-by: Arsh Srivastava <arshsrivastava00@gmail.com>
## t/t6439-merge-co-error-msgs.sh ##
-@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+@@ t/t6439-merge-co-error-msgs.sh: cat >expect <<\EOF
+ error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
- Please commit your changes or stash them before you switch branches.
-+Try using 'git checkout -m <branch>' for a quick fix.
-+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+-Please commit your changes or stash them before you switch branches.
++To move you local changes safely to the other branch,
++Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
-@@ t/t6439-merge-co-error-msgs.sh: error: Your local changes to the following files would be overwritten by checkou
+@@ t/t6439-merge-co-error-msgs.sh: cat >expect <<\EOF
+ error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
- Please commit your changes or stash them before you switch branches.
-+Try using 'git checkout -m <branch>' for a quick fix.
-+Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+-Please commit your changes or stash them before you switch branches.
++To move you local changes safely to the other branch,
++Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
## t/t7406-submodule-update.sh ##
@@ t/t7406-submodule-update.sh: test_expect_success 'submodule update should fail due to local changes' '
+ sed "s/^> //" >expect <<-\EOF &&
> error: Your local changes to the following files would be overwritten by checkout:
> file
- > Please commit your changes or stash them before you switch branches.
-+ > Try using '\''git checkout -m <branch>'\'' for a quick fix.
-+ > Please Note :- that using -m (merge) will not save your changes, rather would directly merge them.
-+ > Meaning if you are not able to resolve conflicts and does --hard reset your local changes would be gone.
+- > Please commit your changes or stash them before you switch branches.
++ > To move you local changes safely to the other branch,
++ > Please try '\''git stash'\'' followed by '\''git checkout <branch>'\'' followed by '\''git stash pop'\'' for safe merge.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
@@ unpack-trees.c: void setup_unpack_trees_porcelain(struct unpack_trees_options *o
? _("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."
++ "To move you local changes safely to the other branch,\n"
++ "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
t/t6439-merge-co-error-msgs.sh | 6 ++++--
t/t7406-submodule-update.sh | 3 ++-
unpack-trees.c | 7 +++++--
3 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/t/t6439-merge-co-error-msgs.sh b/t/t6439-merge-co-error-msgs.sh
index 643c9368e0..6ccc1e0416 100755
--- a/t/t6439-merge-co-error-msgs.sh
+++ b/t/t6439-merge-co-error-msgs.sh
@@ -76,7 +76,8 @@ cat >expect <<\EOF
error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
-Please commit your changes or stash them before you switch branches.
+To move you local changes safely to the other branch,
+Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
@@ -98,7 +99,8 @@ cat >expect <<\EOF
error: Your local changes to the following files would be overwritten by checkout:
rep/one
rep/two
-Please commit your changes or stash them before you switch branches.
+To move you local changes safely to the other branch,
+Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe merge.
Aborting
EOF
diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh
index 3adab12091..1ba15918a5 100755
--- a/t/t7406-submodule-update.sh
+++ b/t/t7406-submodule-update.sh
@@ -211,7 +211,8 @@ test_expect_success 'submodule update should fail due to local changes' '
sed "s/^> //" >expect <<-\EOF &&
> error: Your local changes to the following files would be overwritten by checkout:
> file
- > Please commit your changes or stash them before you switch branches.
+ > To move you local changes safely to the other branch,
+ > Please try '\''git stash'\'' followed by '\''git checkout <branch>'\'' followed by '\''git stash pop'\'' for safe merge.
> Aborting
> fatal: Unable to checkout OID in submodule path '\''submodule'\''
EOF
diff --git a/unpack-trees.c b/unpack-trees.c
index 998a1e6dc7..e817477926 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -128,8 +128,11 @@ 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");
+ "To move you local changes safely to the other branch,\n"
+ "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
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"
base-commit: d181b9354cf85b44455ce3ca9e6af0b9559e0ae2
--
gitgitgadget
^ permalink raw reply related [flat|nested] 62+ messages in thread* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-12 20:05 ` [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails Arsh Srivastava via GitGitGadget
@ 2026-03-12 22:40 ` Junio C Hamano
2026-03-13 3:13 ` Arsh Srivastava
0 siblings, 1 reply; 62+ messages in thread
From: Junio C Hamano @ 2026-03-12 22:40 UTC (permalink / raw)
To: Arsh Srivastava via GitGitGadget
Cc: git, Phillip Wood, Arsh Srivastava, Patrick Steinhardt,
Karthik Nayak
"Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> When a branch switch fails due to local changes and
> new users who are not familiar with the error message often
> get confused about how to move ahead and resolve the issue as
> the previous error message only suggests to commit or stash the changes
> but doesn't explain how to do that or what the next steps are.
The first paragraph is a bit of a run-on and has a misplaced "and";
I cannot quite read and understand this overly long single sentence.
Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
When a branch switch fails due to local changes, new users who
are unfamiliar with the error message often get confused about how
to move ahead and resolve the issue.
Also it is misleading to say "previous" error message. We talk
about the current code in the present tense, to highlight what the
problem in the current code is. The _current_ message stops at
hinting the commands to be used without giving wordy instructions
that are best left to manuals. You may view it as a weakness (which
may motivate this patch to be written). But I personally am not so
sure that adding words to the existing message would necessarily
make it more clear.
> This patch enhances the error message with more specific
> instructions in a concise manner to help users understand
> how to resolve the issue and move their local changes
> safely to the other branch using stash.
As Documentation/SubmittingPatches says, let's instruct the code to
"be like so" in imperative mood. E.g., "Enhance the error
message..." instead of "This patch enhances...".
By the way, the updated message seems much less concise than the
original.
> 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");
> + "To move you local changes safely to the other branch,\n"
> + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
These were already overly long, but the updated one is way too long
to be read on end-user's terminal. The source lines are overly
long, too.
The original was this:
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");
Note that when advice is *NOT* enabled, we only gave
_("Your local changes to the following files would be overwritten by checkout:\n%%s");
without any "advise" in the output. That is what !advice_enabled() means.
The updated code does this:
msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
"To move you local changes safely to the other branch,\n"
"Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
to those users who decline the advice, we now show "Please
commit...". That is not what !advice_enabled() should trigger, is
it?
Also "To move you" -> "To move your".
Also the advice lost the other possiblity of first committing the
work in progress on the original branch before switching, yet the
new advice message is quite wordy.
Also, using "for safe merge" when the user is performing a
"checkout" might be slightly confusing, even if 'stash pop' involves
a merge under the hood.
A more concise version might say:
Try 'git stash && git checkout <branch> && git stash pop' to carry
your changes to the new branch, or commit your work before switching.
But as I already said, I think the current text may already strike
the right balance between being clear and being concise.
Thanks.
^ permalink raw reply [flat|nested] 62+ messages in thread* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-12 22:40 ` Junio C Hamano
@ 2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
` (2 more replies)
0 siblings, 3 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 3:13 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Junio C Hamano <gitster@pobox.com> writes :
> The first paragraph is a bit of a run-on and has a misplaced "and";
> I cannot quite read and understand this overly long single sentence.
> Perhaps the early part can become a bit easier to read with
punctuations, and cutting the sentence into two, e.g.,
In my future commits I will remember to make it as easy to read as possible.
With less punctuations and shorter sentences which will in turn make it more
concise.
> Also it is misleading to say "previous" error message. We talk
> about the current code in the present tense, to highlight what the
> problem in the current code is.
Understood I will in future not use previous because it is the
_current_ code.
> You may view it as a weakness (which
> may motivate this patch to be written). But I personally am not so
> sure that adding words to the existing message would necessarily
> make it more clear.
I understand, git wants people to not explore the available
change options and help them make logical decisions rather
than pushing them with some unneeded commands.
> As Documentation/SubmittingPatches says, let's instruct the code to
> "be like so" in imperative mood. E.g., "Enhance the error
> message..." instead of "This patch enhances...".
Understood that makes sense because nevertheless
it is given that I am writing the changes for this patch only.
> These were already overly long, but the updated one is way too long
> to be read on end-user's terminal. The source lines are overly
> long, too.
That makes total sense.
> to those users who decline the advice, we now show "Please
> commit...". That is not what !advice_enabled() should trigger, is
> it?
Thank you so much for your guidance the advice should not
trigger to those who have opted not to see.
My code might have misjudged this paradigm.
> Also "To move you" -> "To move your".
I thought I had fixed this typo. Seems like I didn't.
I will remember to be more cautious next time.
> Also the advice lost the other possiblity of first committing the
> work in progress on the original branch before switching, yet the
> new advice message is quite wordy.
Absolutely correct this commit does narrow the users vision
for exploring.
> Also, using "for safe merge" when the user is performing a
> "checkout" might be slightly confusing, even if 'stash pop' involves
> a merge under the hood.
I don't want to sound like a programmed robot but I absolutely
agree with the recommendations.
> But as I already said, I think the current text may already strike
> the right balance between being clear and being concise.
Thank you so much for your valuable guidance.
If it's possible I want some guidance over the questions written below,
As it is well stated by you that the current
text is clear enough.
Should I still work on this PR from a purely GSoC
perspective. Or should I start making my proposal or
still work on this PR until my micro project is merged?
Because I have already shown I can navigate git project which
was the goal of micro projects in the first place.
On Fri, 13 Mar 2026 at 04:10, Junio C Hamano <gitster@pobox.com> wrote:
>
> "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> > When a branch switch fails due to local changes and
> > new users who are not familiar with the error message often
> > get confused about how to move ahead and resolve the issue as
> > the previous error message only suggests to commit or stash the changes
> > but doesn't explain how to do that or what the next steps are.
>
> The first paragraph is a bit of a run-on and has a misplaced "and";
> I cannot quite read and understand this overly long single sentence.
>
> Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> When a branch switch fails due to local changes, new users who
> are unfamiliar with the error message often get confused about how
> to move ahead and resolve the issue.
>
> Also it is misleading to say "previous" error message. We talk
> about the current code in the present tense, to highlight what the
> problem in the current code is. The _current_ message stops at
> hinting the commands to be used without giving wordy instructions
> that are best left to manuals. You may view it as a weakness (which
> may motivate this patch to be written). But I personally am not so
> sure that adding words to the existing message would necessarily
> make it more clear.
>
> > This patch enhances the error message with more specific
> > instructions in a concise manner to help users understand
> > how to resolve the issue and move their local changes
> > safely to the other branch using stash.
>
> As Documentation/SubmittingPatches says, let's instruct the code to
> "be like so" in imperative mood. E.g., "Enhance the error
> message..." instead of "This patch enhances...".
>
> By the way, the updated message seems much less concise than the
> original.
>
> > 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");
> > + "To move you local changes safely to the other branch,\n"
> > + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
>
> These were already overly long, but the updated one is way too long
> to be read on end-user's terminal. The source lines are overly
> long, too.
>
> The original was this:
>
> 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");
>
> Note that when advice is *NOT* enabled, we only gave
>
> _("Your local changes to the following files would be overwritten by checkout:\n%%s");
>
> without any "advise" in the output. That is what !advice_enabled() means.
>
> The updated code does this:
>
> msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> "To move you local changes safely to the other branch,\n"
> "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
>
> to those users who decline the advice, we now show "Please
> commit...". That is not what !advice_enabled() should trigger, is
> it?
>
> Also "To move you" -> "To move your".
>
> Also the advice lost the other possiblity of first committing the
> work in progress on the original branch before switching, yet the
> new advice message is quite wordy.
>
> Also, using "for safe merge" when the user is performing a
> "checkout" might be slightly confusing, even if 'stash pop' involves
> a merge under the hood.
>
> A more concise version might say:
>
> Try 'git stash && git checkout <branch> && git stash pop' to carry
> your changes to the new branch, or commit your work before switching.
>
> But as I already said, I think the current text may already strike
> the right balance between being clear and being concise.
>
> Thanks.
>
^ permalink raw reply [flat|nested] 62+ messages in thread* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 3:13 ` Arsh Srivastava
@ 2026-03-13 10:43 ` Karthik Nayak
2026-03-13 11:02 ` Arsh Srivastava
2026-03-13 22:05 ` Junio C Hamano
2026-03-13 10:49 ` Arsh Srivastava
2026-03-13 11:04 ` Arsh Srivastava
2 siblings, 2 replies; 62+ messages in thread
From: Karthik Nayak @ 2026-03-13 10:43 UTC (permalink / raw)
To: Arsh Srivastava, Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt
[-- Attachment #1: Type: text/plain, Size: 3902 bytes --]
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> Junio C Hamano <gitster@pobox.com> writes :
>
>> The first paragraph is a bit of a run-on and has a misplaced "and";
>> I cannot quite read and understand this overly long single sentence.
>> Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> In my future commits I will remember to make it as easy to read as possible.
> With less punctuations and shorter sentences which will in turn make it more
> concise.
>
>> Also it is misleading to say "previous" error message. We talk
>> about the current code in the present tense, to highlight what the
>> problem in the current code is.
>
> Understood I will in future not use previous because it is the
> _current_ code.
>
>> You may view it as a weakness (which
>> may motivate this patch to be written). But I personally am not so
>> sure that adding words to the existing message would necessarily
>> make it more clear.
>
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
>
>> As Documentation/SubmittingPatches says, let's instruct the code to
>> "be like so" in imperative mood. E.g., "Enhance the error
>> message..." instead of "This patch enhances...".
>
> Understood that makes sense because nevertheless
> it is given that I am writing the changes for this patch only.
>
>> These were already overly long, but the updated one is way too long
>> to be read on end-user's terminal. The source lines are overly
>> long, too.
>
> That makes total sense.
>
>> to those users who decline the advice, we now show "Please
>> commit...". That is not what !advice_enabled() should trigger, is
>> it?
>
> Thank you so much for your guidance the advice should not
> trigger to those who have opted not to see.
> My code might have misjudged this paradigm.
>
>> Also "To move you" -> "To move your".
>
> I thought I had fixed this typo. Seems like I didn't.
> I will remember to be more cautious next time.
>
>> Also the advice lost the other possiblity of first committing the
>> work in progress on the original branch before switching, yet the
>> new advice message is quite wordy.
>
> Absolutely correct this commit does narrow the users vision
> for exploring.
>
>> Also, using "for safe merge" when the user is performing a
>> "checkout" might be slightly confusing, even if 'stash pop' involves
>> a merge under the hood.
>
> I don't want to sound like a programmed robot but I absolutely
> agree with the recommendations.
>
>> But as I already said, I think the current text may already strike
>> the right balance between being clear and being concise.
>
> Thank you so much for your valuable guidance.
> If it's possible I want some guidance over the questions written below,
> As it is well stated by you that the current
> text is clear enough.
> Should I still work on this PR from a purely GSoC
> perspective. Or should I start making my proposal or
> still work on this PR until my micro project is merged?
> Because I have already shown I can navigate git project which
> was the goal of micro projects in the first place.
>
From the micro-project information [1] for GSoC we have:
The coding part of the microproject should be very small (say, 10-30
minutes). We don’t require that your patch be accepted into the
“master” branch by the time of your formal application; we mostly want
to see that you have a basic level of competence and especially the
ability to interact with the other Git developers.
As such and seeing Junio's previous response, I would say that no
further work is required here.
[1]: https://git.github.io/General-Microproject-Information/
[snip]
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 690 bytes --]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 10:43 ` Karthik Nayak
@ 2026-03-13 11:02 ` Arsh Srivastava
2026-03-13 22:05 ` Junio C Hamano
1 sibling, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 11:02 UTC (permalink / raw)
To: Karthik Nayak
Cc: Junio C Hamano, Arsh Srivastava via GitGitGadget, git,
Phillip Wood, Patrick Steinhardt
Karthik Nayak <karthik.188@gmail.com> writes :
> We don’t require that your patch be accepted into the
> “master” branch by the time of your formal application
Understandable
> we mostly want to see that you have a basic level of
> competence and especially the
> ability to interact with the other Git developers.
Truly this is something that is very important in any
organization.
> As such and seeing Junio's previous response, I would say that no
> further work is required here.
Thank you so much for your valuable guidance, I will now
draft a formal proposal for GSoC and I look forward to working
with you in the future too. :)
On Fri, 13 Mar 2026 at 16:13, Karthik Nayak <karthik.188@gmail.com> wrote:
>
> Arsh Srivastava <arshsrivastava00@gmail.com> writes:
>
> > Junio C Hamano <gitster@pobox.com> writes :
> >
> >> The first paragraph is a bit of a run-on and has a misplaced "and";
> >> I cannot quite read and understand this overly long single sentence.
> >> Perhaps the early part can become a bit easier to read with
> > punctuations, and cutting the sentence into two, e.g.,
> >
> > In my future commits I will remember to make it as easy to read as possible.
> > With less punctuations and shorter sentences which will in turn make it more
> > concise.
> >
> >> Also it is misleading to say "previous" error message. We talk
> >> about the current code in the present tense, to highlight what the
> >> problem in the current code is.
> >
> > Understood I will in future not use previous because it is the
> > _current_ code.
> >
> >> You may view it as a weakness (which
> >> may motivate this patch to be written). But I personally am not so
> >> sure that adding words to the existing message would necessarily
> >> make it more clear.
> >
> > I understand, git wants people to not explore the available
> > change options and help them make logical decisions rather
> > than pushing them with some unneeded commands.
> >
> >> As Documentation/SubmittingPatches says, let's instruct the code to
> >> "be like so" in imperative mood. E.g., "Enhance the error
> >> message..." instead of "This patch enhances...".
> >
> > Understood that makes sense because nevertheless
> > it is given that I am writing the changes for this patch only.
> >
> >> These were already overly long, but the updated one is way too long
> >> to be read on end-user's terminal. The source lines are overly
> >> long, too.
> >
> > That makes total sense.
> >
> >> to those users who decline the advice, we now show "Please
> >> commit...". That is not what !advice_enabled() should trigger, is
> >> it?
> >
> > Thank you so much for your guidance the advice should not
> > trigger to those who have opted not to see.
> > My code might have misjudged this paradigm.
> >
> >> Also "To move you" -> "To move your".
> >
> > I thought I had fixed this typo. Seems like I didn't.
> > I will remember to be more cautious next time.
> >
> >> Also the advice lost the other possiblity of first committing the
> >> work in progress on the original branch before switching, yet the
> >> new advice message is quite wordy.
> >
> > Absolutely correct this commit does narrow the users vision
> > for exploring.
> >
> >> Also, using "for safe merge" when the user is performing a
> >> "checkout" might be slightly confusing, even if 'stash pop' involves
> >> a merge under the hood.
> >
> > I don't want to sound like a programmed robot but I absolutely
> > agree with the recommendations.
> >
> >> But as I already said, I think the current text may already strike
> >> the right balance between being clear and being concise.
> >
> > Thank you so much for your valuable guidance.
> > If it's possible I want some guidance over the questions written below,
> > As it is well stated by you that the current
> > text is clear enough.
> > Should I still work on this PR from a purely GSoC
> > perspective. Or should I start making my proposal or
> > still work on this PR until my micro project is merged?
> > Because I have already shown I can navigate git project which
> > was the goal of micro projects in the first place.
> >
>
> From the micro-project information [1] for GSoC we have:
>
> The coding part of the microproject should be very small (say, 10-30
> minutes). We don’t require that your patch be accepted into the
> “master” branch by the time of your formal application; we mostly want
> to see that you have a basic level of competence and especially the
> ability to interact with the other Git developers.
>
> As such and seeing Junio's previous response, I would say that no
> further work is required here.
>
> [1]: https://git.github.io/General-Microproject-Information/
>
> [snip]
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 10:43 ` Karthik Nayak
2026-03-13 11:02 ` Arsh Srivastava
@ 2026-03-13 22:05 ` Junio C Hamano
1 sibling, 0 replies; 62+ messages in thread
From: Junio C Hamano @ 2026-03-13 22:05 UTC (permalink / raw)
To: Karthik Nayak
Cc: Arsh Srivastava, Arsh Srivastava via GitGitGadget, git,
Phillip Wood, Patrick Steinhardt
Karthik Nayak <karthik.188@gmail.com> writes:
> From the micro-project information [1] for GSoC we have:
>
> The coding part of the microproject should be very small (say, 10-30
> minutes). We don’t require that your patch be accepted into the
> “master” branch by the time of your formal application; we mostly want
> to see that you have a basic level of competence and especially the
> ability to interact with the other Git developers.
>
> As such and seeing Junio's previous response, I would say that no
> further work is required here.
>
> [1]: https://git.github.io/General-Microproject-Information/
Thanks ;-).
^ permalink raw reply [flat|nested] 62+ messages in thread
* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
@ 2026-03-13 10:49 ` Arsh Srivastava
2026-03-13 11:04 ` Arsh Srivastava
2 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 10:49 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
Actually the above text should be :-
I understand, git wants people to explore the available
change options and help them make logical decisions rather
than pushing them with some unneeded commands.
On Fri, 13 Mar 2026 at 08:43, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> Junio C Hamano <gitster@pobox.com> writes :
>
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> > Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> In my future commits I will remember to make it as easy to read as possible.
> With less punctuations and shorter sentences which will in turn make it more
> concise.
>
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is.
>
> Understood I will in future not use previous because it is the
> _current_ code.
>
> > You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
>
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
>
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
>
> Understood that makes sense because nevertheless
> it is given that I am writing the changes for this patch only.
>
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
>
> That makes total sense.
>
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
>
> Thank you so much for your guidance the advice should not
> trigger to those who have opted not to see.
> My code might have misjudged this paradigm.
>
> > Also "To move you" -> "To move your".
>
> I thought I had fixed this typo. Seems like I didn't.
> I will remember to be more cautious next time.
>
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
>
> Absolutely correct this commit does narrow the users vision
> for exploring.
>
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
>
> I don't want to sound like a programmed robot but I absolutely
> agree with the recommendations.
>
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
>
> Thank you so much for your valuable guidance.
> If it's possible I want some guidance over the questions written below,
> As it is well stated by you that the current
> text is clear enough.
> Should I still work on this PR from a purely GSoC
> perspective. Or should I start making my proposal or
> still work on this PR until my micro project is merged?
> Because I have already shown I can navigate git project which
> was the goal of micro projects in the first place.
>
> On Fri, 13 Mar 2026 at 04:10, Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > When a branch switch fails due to local changes and
> > > new users who are not familiar with the error message often
> > > get confused about how to move ahead and resolve the issue as
> > > the previous error message only suggests to commit or stash the changes
> > > but doesn't explain how to do that or what the next steps are.
> >
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> >
> > Perhaps the early part can become a bit easier to read with
> > punctuations, and cutting the sentence into two, e.g.,
> >
> > When a branch switch fails due to local changes, new users who
> > are unfamiliar with the error message often get confused about how
> > to move ahead and resolve the issue.
> >
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is. The _current_ message stops at
> > hinting the commands to be used without giving wordy instructions
> > that are best left to manuals. You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
> >
> > > This patch enhances the error message with more specific
> > > instructions in a concise manner to help users understand
> > > how to resolve the issue and move their local changes
> > > safely to the other branch using stash.
> >
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
> >
> > By the way, the updated message seems much less concise than the
> > original.
> >
> > > 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");
> > > + "To move you local changes safely to the other branch,\n"
> > > + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
> >
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
> >
> > The original was this:
> >
> > 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");
> >
> > Note that when advice is *NOT* enabled, we only gave
> >
> > _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> >
> > without any "advise" in the output. That is what !advice_enabled() means.
> >
> > The updated code does this:
> >
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "To move you local changes safely to the other branch,\n"
> > "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
> >
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
> >
> > Also "To move you" -> "To move your".
> >
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
> >
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
> >
> > A more concise version might say:
> >
> > Try 'git stash && git checkout <branch> && git stash pop' to carry
> > your changes to the new branch, or commit your work before switching.
> >
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
> >
> > Thanks.
> >
^ permalink raw reply [flat|nested] 62+ messages in thread* Re: [PATCH v7] unpack-trees: suggest using 'git stash' when checkout fails
2026-03-13 3:13 ` Arsh Srivastava
2026-03-13 10:43 ` Karthik Nayak
2026-03-13 10:49 ` Arsh Srivastava
@ 2026-03-13 11:04 ` Arsh Srivastava
2 siblings, 0 replies; 62+ messages in thread
From: Arsh Srivastava @ 2026-03-13 11:04 UTC (permalink / raw)
To: Junio C Hamano
Cc: Arsh Srivastava via GitGitGadget, git, Phillip Wood,
Patrick Steinhardt, Karthik Nayak
Arsh Srivastava <arshsrivastava00@gmail.com> writes:
> I understand, git wants people to not explore the available
This was a typo the real text is :
I understand, git wants people to explore the available
On Fri, 13 Mar 2026 at 08:43, Arsh Srivastava
<arshsrivastava00@gmail.com> wrote:
>
> Junio C Hamano <gitster@pobox.com> writes :
>
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> > Perhaps the early part can become a bit easier to read with
> punctuations, and cutting the sentence into two, e.g.,
>
> In my future commits I will remember to make it as easy to read as possible.
> With less punctuations and shorter sentences which will in turn make it more
> concise.
>
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is.
>
> Understood I will in future not use previous because it is the
> _current_ code.
>
> > You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
>
> I understand, git wants people to not explore the available
> change options and help them make logical decisions rather
> than pushing them with some unneeded commands.
>
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
>
> Understood that makes sense because nevertheless
> it is given that I am writing the changes for this patch only.
>
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
>
> That makes total sense.
>
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
>
> Thank you so much for your guidance the advice should not
> trigger to those who have opted not to see.
> My code might have misjudged this paradigm.
>
> > Also "To move you" -> "To move your".
>
> I thought I had fixed this typo. Seems like I didn't.
> I will remember to be more cautious next time.
>
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
>
> Absolutely correct this commit does narrow the users vision
> for exploring.
>
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
>
> I don't want to sound like a programmed robot but I absolutely
> agree with the recommendations.
>
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
>
> Thank you so much for your valuable guidance.
> If it's possible I want some guidance over the questions written below,
> As it is well stated by you that the current
> text is clear enough.
> Should I still work on this PR from a purely GSoC
> perspective. Or should I start making my proposal or
> still work on this PR until my micro project is merged?
> Because I have already shown I can navigate git project which
> was the goal of micro projects in the first place.
>
> On Fri, 13 Mar 2026 at 04:10, Junio C Hamano <gitster@pobox.com> wrote:
> >
> > "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com> writes:
> >
> > > When a branch switch fails due to local changes and
> > > new users who are not familiar with the error message often
> > > get confused about how to move ahead and resolve the issue as
> > > the previous error message only suggests to commit or stash the changes
> > > but doesn't explain how to do that or what the next steps are.
> >
> > The first paragraph is a bit of a run-on and has a misplaced "and";
> > I cannot quite read and understand this overly long single sentence.
> >
> > Perhaps the early part can become a bit easier to read with
> > punctuations, and cutting the sentence into two, e.g.,
> >
> > When a branch switch fails due to local changes, new users who
> > are unfamiliar with the error message often get confused about how
> > to move ahead and resolve the issue.
> >
> > Also it is misleading to say "previous" error message. We talk
> > about the current code in the present tense, to highlight what the
> > problem in the current code is. The _current_ message stops at
> > hinting the commands to be used without giving wordy instructions
> > that are best left to manuals. You may view it as a weakness (which
> > may motivate this patch to be written). But I personally am not so
> > sure that adding words to the existing message would necessarily
> > make it more clear.
> >
> > > This patch enhances the error message with more specific
> > > instructions in a concise manner to help users understand
> > > how to resolve the issue and move their local changes
> > > safely to the other branch using stash.
> >
> > As Documentation/SubmittingPatches says, let's instruct the code to
> > "be like so" in imperative mood. E.g., "Enhance the error
> > message..." instead of "This patch enhances...".
> >
> > By the way, the updated message seems much less concise than the
> > original.
> >
> > > 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");
> > > + "To move you local changes safely to the other branch,\n"
> > > + "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
> >
> > These were already overly long, but the updated one is way too long
> > to be read on end-user's terminal. The source lines are overly
> > long, too.
> >
> > The original was this:
> >
> > 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");
> >
> > Note that when advice is *NOT* enabled, we only gave
> >
> > _("Your local changes to the following files would be overwritten by checkout:\n%%s");
> >
> > without any "advise" in the output. That is what !advice_enabled() means.
> >
> > The updated code does this:
> >
> > msg = advice_enabled(ADVICE_COMMIT_BEFORE_MERGE)
> > ? _("Your local changes to the following files would be overwritten by checkout:\n%%s"
> > "To move you local changes safely to the other branch,\n"
> > "Please try 'git stash' followed by 'git checkout <branch>' followed by 'git stash pop' for safe 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.");
> >
> > to those users who decline the advice, we now show "Please
> > commit...". That is not what !advice_enabled() should trigger, is
> > it?
> >
> > Also "To move you" -> "To move your".
> >
> > Also the advice lost the other possiblity of first committing the
> > work in progress on the original branch before switching, yet the
> > new advice message is quite wordy.
> >
> > Also, using "for safe merge" when the user is performing a
> > "checkout" might be slightly confusing, even if 'stash pop' involves
> > a merge under the hood.
> >
> > A more concise version might say:
> >
> > Try 'git stash && git checkout <branch> && git stash pop' to carry
> > your changes to the new branch, or commit your work before switching.
> >
> > But as I already said, I think the current text may already strike
> > the right balance between being clear and being concise.
> >
> > Thanks.
> >
^ permalink raw reply [flat|nested] 62+ messages in thread