From: "Arsh Srivastava via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Phillip Wood <phillip.wood123@gmail.com>,
Arsh Srivastava <arshsrivastava00@gmail.com>,
Patrick Steinhardt <ps@pks.im>,
Karthik Nayak <karthik.188@gmail.com>,
Arsh Srivastava <arshsrivastava00@gmail.com>,
Arsh Srivastava <arshsrivastava00@gmail.com>
Subject: [PATCH v5 3/3] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions
Date: Wed, 11 Mar 2026 17:49:29 +0000 [thread overview]
Message-ID: <1cc22f437e92fe522ca23891cf3686c6b4e815c2.1773251369.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2233.v5.git.git.1773251369.gitgitgadget@gmail.com>
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
next prev parent reply other threads:[~2026-03-11 17:49 UTC|newest]
Thread overview: 62+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-10 8:51 [PATCH 0/5] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 8:51 ` [PATCH 1/5] diff: handle ANSI escape codes in prefix when calculating diffstat width LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 2/5] t4052: test for diffstat width when prefix contains ANSI escape codes LorenzoPegorari via GitGitGadget
2026-03-10 8:51 ` [PATCH 3/5] repo: remove unnecessary variable shadow K Jayatheerth via GitGitGadget
2026-03-10 8:51 ` [PATCH 4/5] The 13th batch Junio C Hamano via GitGitGadget
2026-03-10 8:51 ` [PATCH 5/5] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-10 10:33 ` [PATCH 0/5] Advice on checkout dirty files Phillip Wood
2026-03-10 10:42 ` Arsh Srivastava
2026-03-10 10:45 ` Arsh Srivastava
2026-03-10 13:36 ` Junio C Hamano
2026-03-10 13:40 ` Arsh Srivastava
2026-03-10 15:40 ` Junio C Hamano
2026-03-10 16:05 ` Arsh Srivastava
2026-03-10 16:08 ` Arsh Srivastava
2026-03-10 10:59 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
[not found] ` <CAOAgETOebObfZNWA5LWMDxYv8YXYpbrb9L3_ASs_AbQjiQZYZw@mail.gmail.com>
2026-03-10 11:04 ` Arsh Srivastava
2026-03-10 13:16 ` Patrick Steinhardt
2026-03-10 13:36 ` Arsh Srivastava
2026-03-10 14:24 ` Patrick Steinhardt
2026-03-10 13:28 ` [PATCH v3 0/2] Advice on checkout dirty files Arsh Srivastava via GitGitGadget
2026-03-10 13:28 ` [PATCH v3 1/2] advice: add stashBeforeCheckout advice for dirty branch switches Arsh Srivastava via GitGitGadget
2026-03-10 13:43 ` Arsh Srivastava
2026-03-10 13:28 ` [PATCH v3 2/2] advice: add stashBeforeCheckout advice for dirty branch switches [GSOC] Arsh Srivastava via GitGitGadget
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 ` [PATCH v4 3/5] unpack-trees: suggesting 'git checkout -m <branch>' with its repercussions Arsh Srivastava via GitGitGadget
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 ` [PATCH v4 5/5] File updation [GSOC] 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:06 ` Arsh Srivastava
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 [this message]
2026-03-12 1:02 ` [PATCH v5 0/3] Advice on checkout dirty files 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
2026-03-12 16:06 ` Junio C Hamano
2026-03-12 18:13 ` Arsh Srivastava
2026-03-12 18:56 ` Junio C Hamano
2026-03-12 19:03 ` Arsh Srivastava
2026-03-12 19:07 ` Junio C Hamano
2026-03-12 19:12 ` Arsh Srivastava
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
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
2026-03-10 14:31 ` [PATCH v2] advice: add stashBeforeCheckout advice for dirty branch switches Karthik Nayak
2026-03-10 14:37 ` Arsh Srivastava
2026-03-10 14:40 ` Arsh Srivastava
2026-03-10 17:15 ` Karthik Nayak
2026-03-10 18:00 ` Arsh Srivastava
2026-03-10 14:41 ` Arsh Srivastava
2026-03-10 16:48 ` Junio C Hamano
2026-03-10 17:09 ` Karthik Nayak
2026-03-14 4:27 ` Konstantin Ryabitsev
2026-03-10 17:56 ` Arsh Srivastava
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1cc22f437e92fe522ca23891cf3686c6b4e815c2.1773251369.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=arshsrivastava00@gmail.com \
--cc=git@vger.kernel.org \
--cc=karthik.188@gmail.com \
--cc=phillip.wood123@gmail.com \
--cc=ps@pks.im \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.