Subject: Re: [PATCH] checkout: add --autostash option for branch switching

From: Junio C Hamano <[email-masked]>
Date: Mon, 16 Mar 2026 13:04:32 -0700

Phillip Wood <[email-masked]> writes:

> Why is the dry-run of unpack_trees() not an extra check? I was assuming 
> that it was because we do the dry-run and then do it for real after 
> possibly stashing any local changes. That's why I was wondering if we 
> could avoid the dry-run by creating the stash if the non-dry-run 
> unpack_trees() failed.

Ah, I didn't even think about that possibility.

Try to unpack anyway, and if unpack_trees() branch switching
succeeds, we are done.  Otherwise, we can trust that unpack_trees()
did not do _anything_ to the index or the working tree files, so we
can create the stash at that time.

Makes sense.

> It turns out I'd misremembered what "git checkout -m 
> --recurse-submodules" does at the moment - after testing it, it seems to 
> simply nuke an uncommitted submodule changes rather than merging them.

Makes sense.