Apollo Apollo - 2 months ago 14
Git Question

Checkout branch in git submodule

How do I change branches from within a submodule? When I run

git branch
from within the submodule, I see the following output:

> git branch
* (HEAD detached from 229a7b2)
master


How would I put myself on a new branch? Like
development
?

Answer

Simply list your branches:

git branch -avv

And then checkout the one you want

git checkout -b myBranch origin/mybranch

Or create a new development branch from the commit you currently are:

git checkout -b development

A submodule is always checked out as a detached HEAD (meansing at a SHA1)

When you change that, and make any new commit (or change the current commit by a branch checkout), don't forget to:

  • push that commit to the submodule repote repo (its own origin)
  • go to the parent repo, and add, commit and push the new submodule SHA1.
    The parent repo stores said submodule SHA1 as a gitlink, a special entry in its index.
Comments