Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checkout branch in git submodule

Tags:

git

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?

like image 765
Apollo Avatar asked Jan 05 '23 07:01

Apollo


1 Answers

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.
like image 59
VonC Avatar answered Jan 10 '23 13:01

VonC