# Unable to checkout branch that has a new submodule with submodule.recurse

2 messages from 2024-09-20 to 2024-10-31. Participants: Dennis Lubert, Mike Fink.
Thread: https://gitlist.dev/t/62152

## Dennis Lubert, 2024-09-20 10:24

Subject: Unable to checkout branch that has a new submodule with submodule.recurse
Message-ID: <0218f6c7486cb6747a61db4a9d4990eab11f313f.camel@gmx.net>
URL: https://gitlist.dev/e/0218f6c7486cb6747a61db4a9d4990eab11f313f.camel%40gmx.net

```
Hello World,

for years now this has been bothering me. From time to time there is a
new submodule in a branch and when checking that one out with my
standard setup I get something like:

> git checkout branchname

fatal: not a git repository: ../.git/modules/submodule_new
fatal: could not reset submodule index

(this happens on all versions up to 2.46.1 and OS and whatnot I have
access to)

While the workaround is clear (either clone with the desired branch
right away or dont use --recurse-submodules and do update --init
yourself), this is quite unfortunate for people in teams that work
mostly with git integration or gui, also because when this happens it
leaves the repo in an annoying state that needs  a bit more manual
cleanup than --reset hard sometimes and especially for people that just
use the basics this can be overwhelming.

It seems that there is something wrong going on with the order of
creation of the .git file and .git/modules/submodule/config entries,
but I am not deep enough in the details to comment more on that.

To help reproduce the problem reliably (hopefully) I have attached a
shell script. You can run it in an empty directory (please review it
before you do, I hacked it together, it might delete the wrong thing
accidentally). It will need local ssh access (though I think modifying
it to use local repos as submodules could be the same).

greets

Dennis

```

## Mike Fink, 2024-10-31 08:30

Subject: Re: Unable to checkout branch that has a new submodule with submodule.recurse
Message-ID: <17601d47-5d44-4516-b4a0-052a0023d537@gmx.de>
URL: https://gitlist.dev/e/17601d47-5d44-4516-b4a0-052a0023d537%40gmx.de
In-Reply-To: <0218f6c7486cb6747a61db4a9d4990eab11f313f.camel@gmx.net>

```
Hi, comments see inline.
KR, Mike.

On 20.09.24 12:24, Dennis Lubert wrote:
> Hello World,
>
> for years now this has been bothering me. From time to time there is a
> new submodule in a branch and when checking that one out with my
> standard setup I get something like:
>
>> git checkout branchname
>
> fatal: not a git repository: ../.git/modules/submodule_new
> fatal: could not reset submodule index
>
> (this happens on all versions up to 2.46.1 and OS and whatnot I have
> access to)

I do experience the same problem with the current git for windows version.
$ git --version
git version 2.47.0.windows.2

>
> While the workaround is clear (either clone with the desired branch
> right away or dont use --recurse-submodules and do update --init
> yourself), this is quite unfortunate for people in teams that work
> mostly with git integration or gui, also because when this happens it
> leaves the repo in an annoying state that needs  a bit more manual
> cleanup than --reset hard sometimes and especially for people that just
> use the basics this can be overwhelming.
>
> It seems that there is something wrong going on with the order of
> creation of the .git file and .git/modules/submodule/config entries,
> but I am not deep enough in the details to comment more on that.
>
> To help reproduce the problem reliably (hopefully) I have attached a
> shell script. You can run it in an empty directory (please review it
> before you do, I hacked it together, it might delete the wrong thing
> accidentally). It will need local ssh access (though I think modifying
> it to use local repos as submodules could be the same).
>
> greets
>
> Dennis


```
