Subject: [PATCH v10 0/4] checkout: 'autostash' for branch switching

From: "Harald Nordgren via GitGitGadget" <[email-masked]>
Date: Sun, 12 Apr 2026 11:51:41 +0000

Harald Nordgren (4):
  stash: add --label-ours, --label-theirs, --label-base for apply
  sequencer: allow create_autostash to run silently
  sequencer: teach autostash apply to take optional conflict marker
    labels
  checkout: -m (--merge) uses autostash when switching branches

 Documentation/git-checkout.adoc |  58 +++++-----
 Documentation/git-stash.adoc    |  11 +-
 Documentation/git-switch.adoc   |  33 +++---
 builtin/checkout.c              | 138 ++++++++++------------
 builtin/stash.c                 |  32 ++++--
 sequencer.c                     |  67 ++++++++---
 sequencer.h                     |   4 +
 t/t3420-rebase-autostash.sh     |  24 +++-
 t/t3903-stash.sh                |  29 +++++
 t/t7201-co.sh                   | 195 ++++++++++++++++++++++++++++++++
 t/t7600-merge.sh                |   2 +-
 xdiff-interface.c               |  12 ++
 xdiff-interface.h               |   1 +
 xdiff/xmerge.c                  |   6 +-
 14 files changed, 455 insertions(+), 157 deletions(-)

base-commit: 8c9303b1ffae5b745d1b0a1f98330cf7944d8db0
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2234%2FHaraldNordgren%2Fcheckout_autostash-v10
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2234/HaraldNordgren/checkout_autostash-v10
Pull-Request: https://github.com/git/git/pull/2234

Range-diff vs v9:

 1:  5d5dc1f60e = 1:  aa519c50be stash: add --label-ours, --label-theirs, --label-base for apply
 2:  a1fa04a965 = 2:  8173a4eb72 sequencer: allow create_autostash to run silently
 3:  87216a633b = 3:  f36fedd8c2 sequencer: teach autostash apply to take optional conflict marker labels
 4:  00e0b3196c ! 4:  b6e5546d74 checkout: -m (--merge) uses autostash when switching branches
     @@ builtin/checkout.c: static int switch_branches(const struct checkout_opts *opts,
       		ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
      +		if (ret && opts->merge) {
      +			create_autostash_ref_silent(the_repository,
     -+						   "CHECKOUT_AUTOSTASH");
     ++						   "CHECKOUT_AUTOSTASH_HEAD");
      +			created_autostash = 1;
      +			ret = merge_working_tree(opts, &old_branch_info, new_branch_info, &writeout_error);
      +		}
       		if (ret) {
      +			apply_autostash_ref_with_labels(the_repository,
     -+						       "CHECKOUT_AUTOSTASH",
     ++						       "CHECKOUT_AUTOSTASH_HEAD",
      +						       new_branch_info->name,
      +						       "local",
      +						       stash_label_base);
     @@ builtin/checkout.c: static int switch_branches(const struct checkout_opts *opts,
      +		git_config_push_parameter(cfg.buf);
      +		strbuf_release(&cfg);
      +	}
     -+	apply_autostash_ref_with_labels(the_repository, "CHECKOUT_AUTOSTASH",
     ++	apply_autostash_ref_with_labels(the_repository, "CHECKOUT_AUTOSTASH_HEAD",
      +				       new_branch_info->name, "local",
      +				       stash_label_base);
      +

-- 
gitgitgadget