Re: [PATCH v2] checkout: add --autostash option for branch switching
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 12, 2026, 19:50 UTC
- Message-ID
- <xmqqjyvgesjx.fsf@gitster.g>
- In-Reply-To
- <pull.2234.v2.git.git.1773344022931.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 17 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com> > > When switching branches, local modifications in the working tree can > prevent the checkout from succeeding. While "git rebase" and "git > merge" already support --autostash to handle this case automatically, > "git checkout" and "git switch" require users to manually stash and > unstash their changes. > > Teach "git checkout" and "git switch" to accept --autostash and > --no-autostash options that automatically create a temporary stash > entry before the branch switch begins and apply it after the switch > completes. If the stash application results in conflicts, the stash > entry is saved to the stash list so the user can resolve them later. > > Also add a checkout.autoStash configuration option that enables this > behavior by default, which can be overridden with --no-autostash on > the command line.
With this, shouldn't "-m" become a synonym for "--autostash"? For users of "checkout -m", this is a strictly improved version of the same feature, it seems.
Also, "stash" is merely an implementation detail of how we make the merge safer, so from end-user's point of view, this feature is more like "switch to the other branch, while merging the local changes there", so calling it "--merge" or something may be much better than calling it "--autostash".
Other than that, I like the implementation in general.