]> git.ipfire.org Git - thirdparty/git.git/commit
checkout: -m (--merge) uses autostash when switching branches
authorHarald Nordgren <haraldnordgren@gmail.com>
Sun, 12 Apr 2026 11:51:45 +0000 (11:51 +0000)
committerJunio C Hamano <gitster@pobox.com>
Sun, 12 Apr 2026 22:11:39 +0000 (15:11 -0700)
commit887156319fae267d6ae00a9f0f2af142e055a25d
tree9acd3e50c3bc8b6f32a7adeef5f50c5ef28fc949
parent9cf8eac2bd2341769fd022f7211d3435cbde4ba9
checkout: -m (--merge) uses autostash when switching branches

When switching branches with "git checkout -m", local modifications
can block the switch.  Teach the -m flow to create a temporary stash
before switching and reapply it after.  On success, only "Applied
autostash." is shown.  If reapplying causes conflicts, the stash is
kept and the user is told they can resolve and run "git stash drop",
or run "git reset --hard" and later "git stash pop" to recover their
changes.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-checkout.adoc
Documentation/git-switch.adoc
builtin/checkout.c
sequencer.c
t/t3420-rebase-autostash.sh
t/t7201-co.sh
t/t7600-merge.sh
xdiff-interface.c
xdiff-interface.h