threads / discuss / 62152

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

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

## tl;dr

2 messages between Sep 20, 2024 and Oct 31, 2024.

replies: 1people: 2as markdown or json

Dennis Lubert· Sep 20, 2024, 10:24 UTC · lore
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· Oct 31, 2024, 08:30 UTC · re: Dennis Lubert · lore

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

Hi, comments see inline. KR, Mike.

On 20.09.24 12:24, Dennis Lubert wrote:
Show 13 quoted lines
> 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

Show 22 quoted lines
>
> 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

← back to recent threads