Apollo
Apollo

Reputation: 9054

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?

Upvotes: 5

Views: 13740

Answers (1)

VonC
VonC

Reputation: 1324148

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 remote repository (its own origin)
  • go to the parent repository, and add, commit and push the new submodule SHA1.
    The parent repository stores said submodule SHA1 as a gitlink, a special entry in its index.

Upvotes: 11

Related Questions