From: Phillip Wood Date: Fri, 13 Mar 2026 14:29:45 GMT Subject: Re: [PATCH] checkout: add --autostash option for branch switching Message-ID: <953b5842-a4ae-40f6-8cae-c4f81239c903@gmail.com> In-Reply-To: On 12/03/2026 14:40, Junio C Hamano wrote: > > Perhaps doing it this way would make it more worth doing? > > - At the beginning of branch switching, ask a new helper function > that takes the branch we are switching to as an argument this > question: > > Do any paths that are different between the current branch and > the branch we are switching to have local (i.e., either in the > index or in the working tree) change [Yes/No]? > > - When the answer is "yes", save the local changes to a new stash > entry, and clear the local changes from the index and from the > working tree. If not, do not bother with stash at all. Can we avoid the extra check and stash if the user passed "--autostash" and unpack_trees() fails because it would overwrite local changes in merge_working_tree()? > If we can sell it as an improved implementation of "-m", we probably > can lose some code that the current "-m" implementation uses to do > its merge; we'd be instead using the "unstash" code paths. That would be nice but I think "git checkout --recurse-submodules -m " currently updates submodules whereas "git stash" does not know how to recurse submodules. It would be nice to teach "git stash" to recurse submodules but I don't think it is completly straight forward as we'd need to store the object id of the submodule's stash commit in the parent stash. Thanks Phillip