0

Parent repo - a separate branch submodule repo - a separate branch

In Bitbucket Every time I push a commit to the submodule I need to update the parent repo to the latest commit in the submodule.

This is because when I used the submodule, my parent branch is pointing to a commit, now my question is can we point the parent branch to a submodule branch rather than to a commit.

currently, my .gitmodule file in my parent repo looks like following

[submodule “arch/modules”]
    path = arch/modules
    url = https://bitbucket.xxx.xxxx/scm/archdev/modules.git
    branch = arch/module-test

even when I pointed that to a branch , why it is still referring to a commit ?? Is there a way to make the parent repo branch point to a submodule repo branch.

Can someone address this please

Thanks in advance

Bala krishna
  • 519
  • 1
  • 10
  • 24
  • 1
    Branches never point to branches: not within a repository, not across repositories. A branch name *in* a repository simply holds a commit hash ID. Similarly, submodules always refer to commits by hash ID. That `branch =` setting is there **only** for `git submodule update --remote`. – torek Aug 17 '21 at 09:25
  • 1
    The reason for this is simple enough: Git really doesn't care about branches. Branch names are meaningless and irrelevant; only *commit hash IDs* really matter. Branches therefore don't have parent branches, they just have commit hash IDs. – torek Aug 17 '21 at 09:27
  • @torek, thanks for commenting but the reason I am checking this is, we rigorously make changes to the submodule repo, because of this we need to update the parent repo also manually to the latest commit of the submodule every time, this is very time-consuming. I want a way to automatically update the parent repo to latest commit of submodule – Bala krishna Aug 17 '21 at 09:28
  • 1
    Write yourself a script. You can use `git submodule update --remote` *in* the script (that's the one place that Git actually uses these settings), or you can write your own code to update the submodules to the correct commits; then do the appropriate `git add`s in the superproject and run `git commit`. You now have a script that does the update. Git does not come with one. – torek Aug 17 '21 at 09:29
  • 1
    Does this answer your question? [Why is my Git Submodule HEAD detached from master?](https://stackoverflow.com/questions/18770545/why-is-my-git-submodule-head-detached-from-master) – Simba Aug 17 '21 at 09:30
  • I have multiple parent repo's which need to be updated whenever there is a change in submodule repo , and also how that script needs to run whenever there is a change in submodule – Bala krishna Aug 17 '21 at 09:30
  • 1
    @Balakrishna: *I have multiple parent repos which need to be updated...* I didn't say writing the script would be *easy*. There's a reason Git doesn't come with one. – torek Aug 17 '21 at 09:47

1 Answers1

0

Nope. You don't understand what git submodule is.

Git submodule is a way to include another project into current project. The project has to contain a specific state for the submodule in each of the project's commit. This is done by referring to a specific commit of the submodule.

To do it in git command, it's equivalent to

  1. git clone url://submodule path/to/sub, and
  2. cd path/to submodule
  3. git checkout submodule-commitid

This causes the HEAD of submodule detached from branch.

Why is my Git Submodule HEAD detached from master?

Simba
  • 23,537
  • 7
  • 64
  • 76