git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v5 0/3] Advice on checkout dirty files

From
Arsh Srivastava via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 11, 2026, 17:49 UTC
Message-ID
<pull.2233.v5.git.git.1773251369.gitgitgadget@gmail.com>
In-Reply-To
<pull.2233.v4.git.git.1773219028.gitgitgadget@gmail.com>
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
Previous: Arsh SrivastavaNext: Arsh Srivastava via GitGitGadget
Message 41 of 62 in “Advice on checkout dirty files”
  1. 0/5 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 10, 2026
  2. 1/5 diff: handle ANSI escape codes in prefix when calculating diffstat widthLorenzoPegorari via GitGitGadget, Mar 10, 2026
  3. 2/5 t4052: test for diffstat width when prefix contains ANSI escape codesLorenzoPegorari via GitGitGadget, Mar 10, 2026
  4. 3/5 repo: remove unnecessary variable shadowK Jayatheerth via GitGitGadget, Mar 10, 2026
  5. 4/5 The 13th batchJunio C Hamano via GitGitGadget, Mar 10, 2026
  6. 5/5 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 10, 2026
  7. Phillip WoodMar 10, 2026
  8. Arsh SrivastavaMar 10, 2026
  9. Arsh SrivastavaMar 10, 2026
  10. advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 10, 2026
  11. Arsh SrivastavaMar 10, 2026
  12. Patrick SteinhardtMar 10, 2026
  13. 0/2 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 10, 2026
  14. 1/2 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 10, 2026
  15. 2/2 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]Arsh Srivastava via GitGitGadget, Mar 10, 2026
  16. Junio C HamanoMar 10, 2026
  17. Arsh SrivastavaMar 10, 2026
  18. Arsh SrivastavaMar 10, 2026
  19. Arsh SrivastavaMar 10, 2026
  20. Patrick SteinhardtMar 10, 2026
  21. Karthik NayakMar 10, 2026
  22. Arsh SrivastavaMar 10, 2026
  23. Arsh SrivastavaMar 10, 2026
  24. Arsh SrivastavaMar 10, 2026
  25. Junio C HamanoMar 10, 2026
  26. Arsh SrivastavaMar 10, 2026
  27. Arsh SrivastavaMar 10, 2026
  28. Junio C HamanoMar 10, 2026
  29. Karthik NayakMar 10, 2026
  30. Karthik NayakMar 10, 2026
  31. Arsh SrivastavaMar 10, 2026
  32. Arsh SrivastavaMar 10, 2026
  33. 0/5 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 11, 2026
  34. 1/5 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 11, 2026
  35. 2/5 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  36. 3/5 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussionsArsh Srivastava via GitGitGadget, Mar 11, 2026
  37. 4/5 Updating tests and unpack-tress.c [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  38. 5/5 File updation [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  39. Junio C HamanoMar 11, 2026
  40. Arsh SrivastavaMar 11, 2026
  41. 0/3 Advice on checkout dirty filesArsh Srivastava via GitGitGadget, Mar 11, 2026
  42. 1/3 advice: add stashBeforeCheckout advice for dirty branch switchesArsh Srivastava via GitGitGadget, Mar 11, 2026
  43. 2/3 advice: add stashBeforeCheckout advice for dirty branch switches [GSOC]Arsh Srivastava via GitGitGadget, Mar 11, 2026
  44. 3/3 unpack-trees: suggesting 'git checkout -m <branch>' with its repercussionsArsh Srivastava via GitGitGadget, Mar 11, 2026
  45. Junio C HamanoMar 12, 2026
  46. Arsh SrivastavaMar 12, 2026
  47. unpack-trees: suggesting 'git checkout -m' with its repercussionsArsh Srivastava via GitGitGadget, Mar 12, 2026
  48. Junio C HamanoMar 12, 2026
  49. Arsh SrivastavaMar 12, 2026
  50. Junio C HamanoMar 12, 2026
  51. Arsh SrivastavaMar 12, 2026
  52. Junio C HamanoMar 12, 2026
  53. Arsh SrivastavaMar 12, 2026
  54. unpack-trees: suggest using 'git stash' when checkout failsArsh Srivastava via GitGitGadget, Mar 12, 2026
  55. Junio C HamanoMar 12, 2026
  56. Arsh SrivastavaMar 13, 2026
  57. Karthik NayakMar 13, 2026
  58. Arsh SrivastavaMar 13, 2026
  59. Arsh SrivastavaMar 13, 2026
  60. Arsh SrivastavaMar 13, 2026
  61. Junio C HamanoMar 13, 2026
  62. Konstantin RyabitsevMar 14, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.