desktop: Switching to a branch with submodules is not possible

Describe the bug

If GitHub Desktop cloned a repository on a branch without submodules, when attempting to switch to a branch with submodules, GitHub Desktop throws the following error:

fatal: not a git repository: ../.git/modules/<submodule name>
fatal: could not reset submodule index

Additionally, after the attempt, GitHub Desktop creates a .gitmodules file with the following contents:

[submodule "<submodule name>"]
    path = <submodule name>
    url = <submodule url>

The workaround for this issue is to remove the following lines from .git/config before attempting a branch checkout:

[submodule]
    active = .

If a checkout attempt is done before the removal, the workaround won’t work. The submodule won’t get initialized and updated on checkout any more, even after removing those lines and clearing up the leftovers.

Version & OS

Version 2.9.3 (x64) Windows 10 Enterprise, version 1809, build 17763.2114

Steps to reproduce the behavior

  1. Create a repository with a default branch set to a branch without any submodules.
  2. Create a branch in the repository and add a submodule to it.
  3. Checkout this repository with GitHub Desktop. It should checkout the default branch without submodules.
  4. Try checking out the submodule branch. GitHub Desktop should throw the error mentioned at the top of this page.

Expected behavior

I believe GitHub Desktop should run git submodule update --init --recursive on every branch checkout and clone. I believe this would guarantee that submodules are always initialized and set to proper commits depending on a given branch.

Actual behavior

GitHub Desktop throws and error and refuses to checkout the branch.

Screenshots

Not possible due to company policy.

Logs

Not possible due to company policy.

Additional context

N/A

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 48 (7 by maintainers)

Most upvoted comments

For those facing this issue in Desktop and Terminal. I was able to workaround it by cloning the repository directly into the branch.

Step 1: git clone -b {branch_name} {repo_url}

Step 2: Initialise Submodule

git submodule init
git submodule update

Step 3: Add the Existing repo in Github Desktop

This is not solved. Please re-open the issue. The same error is coming in the latest release 3.1.3

This is not solved (v3.1.5). +1

Does that happen to you when you switch to a branch like that from the command line?

Yes

It’s ridiculous that this is very clearly still an issue and it’s marked as closed. My users run into this and similar issues constantly with regard to Github Desktop’s disastrous handling of submodules across the board.

Still an issue

I am also experiencing this issue on Github for Windows 3.3.9

+1

Still an issue for me too.

@DerekZiemba recurse-submodules does not always work and in thoses cases can be replaced by a reinit afterwards. Try

git -c submodule.recurse=false checkout -f boost-1.70.0
git submodule update --init --recursive

Only found out myself about this recently, and now I’m wondering if maybe this is related to this issue in Github Desktop (which I’m not using myself).

For the record, in my case the issue was solved after updating the version of git (which is unrelated to the version of github desktop).

I also experience it, 3.2.0 on Windows 10.

It appends when i switch from my Main branch to the branch containing submodules…

fatal: not a git repository: Assets/External/Logiked/LogikedBundle/…/…/…/…/.git/modules/Assets/External/Logiked/LogikedBundle fatal: could not reset submodule index