# git checkout --recurse-submodules deletes local modifications

1 messages from 2023-12-06 to 2023-12-06. Participants: Simon Etter.
Thread: https://gitlist.dev/t/60585

## Simon Etter, 2023-12-06 07:16

Subject: git checkout --recurse-submodules deletes local modifications
Message-ID: <CAFy4k4JpyqWCDH48YZJ6wc6nhtUq7J43ZHwg8-LDTQfDMsMqSg@mail.gmail.com>
URL: https://gitlist.dev/e/CAFy4k4JpyqWCDH48YZJ6wc6nhtUq7J43ZHwg8-LDTQfDMsMqSg%40mail.gmail.com

```
Hi there!

It seems git checkout --recurse-submodules doesn't live up to its
documentation. According to the docs:

> If local modifications in a submodule would be overwritten the checkout will fail unless -f is used.

Here's an MWE where git checkout --recurse-submodules does overwrite
local modifications:

ˋˋˋ
# Prepare repo
rm -rf /tmp/test
mkdir /tmp/test
cd /tmp/test
git init
git submodule add git@github.com:octocat/Hello-World.git
git commit -m "Add submodule"
git checkout -b other
cd Hello-World
git checkout 762941318ee16e59dabbacb1b4049eec22f0d303
cd ..
git add Hello-World
git commit -m "Change submodule commit"

# Add local modification
echo boo! > Hello-World/README

# Switch branches. This completes without error, and deletes the
change introduced in the previous line.
git checkout main --recurse-submodules
ˋˋˋ

I believe part of the problem is that
762941318ee16e59dabbacb1b4049eec22f0d303 and
7fd1a60b01f91b314f59955a4e4d4e80d8edf11d (the Hello-World master
commit) are the same; the last line does report an error if I make
`other` point at 553c2077f0edc3d5dc5d17262f6aa498e69d6f8e instead of
the above commit. However, I don't think this changes the fact that
the above MWE makes git checkout --recurse-submodules look pretty
dangerous.

I'd love to hear if

1) the above is intended behavior,
2) I'm doing something wrong, or
3) this is a bug.

Best regards, and thanks for all your hard work,
Simon

```
