1

I'm tinkering with a library which is a part of a larger library collection, where the larger collection is a git(hub) repo, and so is the individual library; but - you have to clone the entire collection, with the specific library as a subrepo, just in order to work on the individual library, for various reasons (see my last question about setting this up).

So, I'm making changes to the repo code, which is checked out as a submodule. But - I notice I'm on a "detached head", i.e. if I commit - I can't just push it to the relevant branch on the library's remote repository.

  • Can I arrange it so that commits do not, by default for this specific checked-out submodule, create a new detached head?
  • If not, what's the right way to push my changes to the repository?
einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • Commits donot create a detached head. You were on one before the commit. Simply checkout the desired branch before committing. – sehe Feb 11 '18 at 04:05

1 Answers1

2

You can make sure your submodule does track a branch.
See also "Git submodules: Specify a branch/tag"

cd /path/to/your/parent/repo
git config -f .gitmodules submodule.<path>.branch <branch>

From there, any git submodule update --recursive --remote would update the submodule to the latest of that branch, from where you can make new commits and push back.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • If my submodule is named `my_sm` and is in a subdirectory of the parent repo named `my_subdir1/my_subdir2` and the submodule repo branch I want to track is `my_sm_branch`, then should I write `git config -f .gitmodules submodule.my_subdir1/my_subdir2.branch my_sm_branch`? – einpoklum Feb 11 '18 at 09:00
  • @einpoklum Yes, that is the idea. – VonC Feb 11 '18 at 09:55