{"thread":{"id":"48707","subject":"fatal: could not reset submodule index","startedAt":"2018-06-13T22:18:05Z","lastAt":"2018-06-13T22:18:05Z","messageCount":1,"participants":["Antoine W. Campagna"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"350097","messageId":"DB6PR0101MB2344147D4749598823B094F1D97E0@DB6PR0101MB2344.eurprd01.prod.exchangelabs.com","threadId":"48707","inReplyTo":null,"subject":"fatal: could not reset submodule index","fromName":"Antoine W. Campagna","fromEmail":"awe@frontmatec.com","sentAt":"2018-06-13T22:17:58Z","receivedAt":"2018-06-13T22:18:05Z","isPatch":false,"sender":{"key":"awe@frontmatec.com","avatar":"https://gravatar.com/avatar/7c7bfeb735f281887abfd8ab6177d7b747ec5aad84d2fa003f82a6a81e38be81?d=mp&s=160"},"body":"Hi,\n\nI would like to add submodules to existing projects.\nSome branches would have the submodules and some branches would not.\nSince we often switch from one branch to another, I would like the submodules to update automatically so I activate the option submodule.recurse.\nBut I am experiencing a problem if I do the following:\n  1. Clone repo, with master containing no submodules\n  2. Checkout a branch that contains submodules. It results in this error:\n\tfatal: not a git repository: ../.git/modules/submodule\n\tfatal: could not reset submodule index\nI think git is trying to update the submodule but the submodule has not yet been initialized (runs \"git submodule update\" without \"--init\").\nIs there a way to ask git to initialize the submodule automatically ?\n\n\nHere is the full reproduction instructions:\n\n# Create a repository\nmkdir main\ncd main\ngit init\ntouch main.txt\ngit add main.txt\ngit commit -a -m \"Initial commit\"\ncd ..\n\n# Create a second repository\nmkdir sub\ncd sub\ngit init\ntouch sub.txt\ngit add sub.txt\ngit commit -a -m \"Initial commit of repo sub\"\ncd ..\n\n# Add the second repository as submodule, on a separate branch\ncd main\ngit branch with-submodule\ngit checkout with-submodule\ngit submodule add ../sub sub\ngit commit -a -m \"Add submodule\"\n\n# Set main repo back to master branch (without the submodule)\ngit checkout master\ncd ..\n\n# Make a clone and checkout the branch\ngit clone main clone1\ncd clone1\ngit checkout with-submodule\n# Submodule is not automatically updated (sub folder is empty)\ngit submodule update --init --recursive\n# Now the submodule content is there\n# But I want to automatically update submodules when checking out a branch\ncd ..\n\n# Trying again, adding --recursive during clone\ngit clone --recursive main clone2\ncd clone2\ngit checkout with-submodule\n# Submodule is still not automatically updated (sub folder is empty)\ngit submodule update --init --recursive\ncd ..\n\n# Trying again, adding --recurse-submodules during checkout\ngit clone --recursive main clone3\ncd clone3\ngit checkout --recurse-submodules with-submodule\n# Fails with these error messages :\n#\tfatal: not a git repository: ../.git/modules/sub\n#\tfatal: could not reset submodule index\n# It seems like Git tries to update the submodule but without having initialized the submodule\ncd ..\n\n# Trying again with submodule.recurse\ngit config --global submodule.recurse true\ngit clone main clone4\ncd clone4\ngit checkout with-submodule\n# Submodule is still not automatically updated (sub folder is empty)\n# It seems like submodule.recurse does not affect git clone\n\n# Trying again with both submodule.recurse and --recursive\ngit config --global submodule.recurse true\ngit clone --recursive main clone5\ncd clone5\ngit checkout with-submodule\n# Fails with these error messages :\n#\tfatal: not a git repository: ../.git/modules/sub\n#\tfatal: could not reset submodule index\n# Same issue as with \"git checkout --recurse-submodules\"\n\n# I tested this in git-bash on Windows 10\n$ git --version\n\tgit version 2.17.1.windows.2\n# And in Ubuntu in WSL\n$ git --version\n\tgit version 2.17.1\n\n"}]}