# [BUG] git checkout --recurse-submodules on initialized but not cloned submodule fails badly

1 messages from 2021-08-08 to 2021-08-08. Participants: Alexey Izbyshev.
Thread: https://gitlist.dev/t/56238

## Alexey Izbyshev, 2021-08-08 22:21

Subject: [BUG] git checkout --recurse-submodules on initialized but not cloned submodule fails badly
Message-ID: <85faefc0b1e23ee942b11087089ccc4f@ispras.ru>
URL: https://gitlist.dev/e/85faefc0b1e23ee942b11087089ccc4f%40ispras.ru

```
Hi,

On a fresh clone of a repo with submodules, running `git checkout 
--recurse-submodules` after `git submodule init` but without `git 
submodule update` fails (as expected), but leaves the working tree in a 
bad state:

git init repo
git -C repo commit --allow-empty -m "initial"
git -C repo submodule add "$PWD"/repo
git -C repo commit -m "add sm"
git clone repo repo-clone
git -C repo-clone submodule init repo
git -C repo-clone checkout --recurse-submodules repo
fatal: not a git repository: ../.git/modules/repo
fatal: could not reset submodule index

(Tested on git 2.17.1 and v2.33.0-rc1)

`git checkout` creates a gitlink in the submodule directory even though 
its target is not a valid git dir (it contains only `config`). In the 
resulting state, many git commands (like `status` and even `submodule 
deinit`) fail, so while trying to checkout a submodule before `submodule 
update` isn't supposed to work, I think it still shouldn't leave the 
repo in such a state.

It seems that related issues have already been reported, though those 
that I've found[1,2,3] describe more complex scenarios, while mine is 
very basic.

Hope it helps,
Alexey

[1] 
https://public-inbox.org/git/20200501005432.h62dnpkx7feb7rto@glandium.org/
[2] 
https://public-inbox.org/git/dab7128d-5ea7-5d7c-1ae1-1d71be316326@gmail.com/
[3] 
https://public-inbox.org/git/CABVQXt5E-R22G62W-tQieA7XiZKZiOA8Hp2xewYhwwOS8wFh0Q@mail.gmail.com/


```
