Search code examples
gitgit-submodules

Git submodule keeps resetting to (no branch)


I've removed and re-added the submodule over and over and over, but everytime we clone the parent repository, the submodule is at "(no branch)" Can someone provide the steps to get a submodule and properly, definitively, without any doubt, lock it on a commit?

Steps I took:

  • git submodule add https://bitbucket.org/bla/bla.git my/submodule/path
  • Update the submodule to point to a latest commit in a branch. Commit message says From <hash> X months ago Initial commit To: <hash> 1 day ago <somemessage>
  • Pushed the changes
  • git clone on a colleague's computer git clone https://bitbucket.org/bla/bla.git

The submodule is on (no branch) on my colleague's computer. It should not be. It should be at the commit I put it at. What have I missed?

Edit So maybe "(no branch)" is just misleading. On my colleague's machine, it checks out at Initial commit. That's the core problem.


Solution

  • Well, this is embarrassing, it took us way too long to figure this out because we weren't reading properly, as you can already tell from the question.

    The reason it worked fine on my machine and not on my colleague's machine is because I was using https to check out the repository and he was using SSH. The submodule was included with a https url and that failed. I used the relative path as suggested here https://stackoverflow.com/a/48067316/1980516