Apollo Apollo - 1 year ago 98
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)

How would I put myself on a new branch? Like

Answer Source

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.
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download