0

I am setting up a git-repository that will be used by 5-10 developers I have setup a few submodules within my main repository, but it seems they do not automatically track a branch upon recursive clone. The main problem is to avoid developers committing outside a branch (i.e. headless)

I believe i have added the submodules the way other StackOverflow post suggest you should setup branch tracking. e.g. git submodule tracking latest

i use git 2.7.4 and add with the commands

git submodule add -b ${submodule_branch} ../../${submodule_repo_path}.git ${submodule_path}
git submodule update --remote

When i call 'git branch' within one of the submodules it clearly show that i am on a branch.

git branch
* master

I commit this change and push to the remote 'git push origin --mirror --force'

The server is BitBucket v5.3.0

When i clone with 'git clone --recursive' i get all the repo and the .gitmodules looks right, it mentions the branch

[submodule "some_app"]
path = some_app
url = ../../some_app.git
branch = master

However within the submodule it looks like it is detached:

somepath/some_app ((487b858...))
$ git branch
git branch
* (HEAD detached at 487b858)
  master

I can make a workaround by checking out the correct branch in each submodule, but i do not think it should be needed.

i have also tried to call

git submodule update --remote

after cloning, but it did not help

Is it normal practice that you must first checkout a branch when working with submodules?

  • Submodules add an additional level of complexity for developers who need to make updates to the submodule. – crashmstr Dec 08 '17 at 12:44

1 Answers1

1

From which folder did you try the submodules update command? I guess without testing that this is one of the cases you should at least be in the main repository containing the subrepositories and not within one of them.

The detach behavior is the wished behavior. When you look at the file that represents the submodule folder you'll see the commit hash from the time the submodule was added. When you do a git submodule update --remote you'll also see that you have to commit the updates, which means that git will write the now newest commit hash to the file. This allows you to go to a specific commit of the submodule.

I needed some time to get used to it. You should definitly read the submodules chapter of the git scm book. It gives you some tips and tricks (and commands/settings) that help you using submodules.

Hoall
  • 184
  • 16
  • i have tried the submodule update BOTH in the root and the submodule folder. It is fair enough i need to perform 2x commits. It is just annoying that you by default is not on any branch. So far make a script which checkout the branches of each submodule. – Steffen Villadsen Dec 08 '17 at 13:01