2

I can't get submodules to checkout the correct branch, they always end up in a specific, old commit.

Example: I have a repo which has 3 submodules, linked in the .gitmodules:

[submodule "repo-web"]
    path = repo-web
    url = git@github.com:Project/repo-web.git
    branch = task/test_install
[submodule "report-templates"]
    path = report-templates
    url = git@github.com:Project/report-templates.git
    branch = master
[submodule "Project-python"]
    path = Project-python
    url = git@github.com:Project/Project-python.git
    branch = dev

When I do a fresh install of the repo and download the submodules by either

git submodule update --init --recursive --remote
or
git clone --recursive https://github.com/Project/repo.git

the submodules seem to be linked to specific commit, all 3 of them alway end up with a detached head. Also, when I look at them at Github, they all have the format

repo-web @ ce80174

which is the commit that they are linked to.

.git.config:

[submodule "repo-web"]                                                                                                                                                                            
       url = git@github.com:Project/repo-web.git

How to get the correct branch?

juettemann
  • 323
  • 2
  • 14
  • https://stackoverflow.com/a/18797720/7976758 found in https://stackoverflow.com/search?q=%5Bgit-submodules%5D+branch The bottom line: do not rely on that branch configuration too much. – phd Oct 14 '21 at 11:36
  • 1
    That's how submodules are intended to work. That's probably not how *you* wanted them to work. This is one of many reasons some people call them "sob-modules". There is ongoing work on Git right now to address some of the many issues with submodules, but my own take on this is shorter: whatever the problem is, submodules are the wrong answer. Sometimes they're the only answer, but it's still wrong... – torek Oct 14 '21 at 12:41
  • Thanks to both that was actually helpful. I only encountered submodules a few days ago, sob-modules is fitting ;) – juettemann Oct 14 '21 at 14:16

0 Answers0