![]() ![]() To ensure the branch is actually checked out (and that won’t modify the SHA1 of the special entry representing the submodule for the parent repo), he suggests: git submodule foreach -q -recursive 'branch="$(git config -f $toplevel/.gitmodules submodule.$name.branch)" git switch $branch'Įach submodule will still reference the same SHA1, but if you do make new commits, you will be able to push them because they will be referenced by the branch you want the submodule to track.Īfter that push within a submodule, don’t forget to go back to the parent repo, add, commit and push the new SHA1 for those modified submodules. (Clintm notes in the comments that, if you run git submodule update -remote and the resulting sha1 is the same as the branch the submodule is currently on, it won’t do anything and leave the submodule still “on that branch” and not in detached head state.) Note that the result, for each updated submodule, will almost always be a detached HEAD, as Dan Cameron note in his answer. If you want to update all your submodules following a branch: git submodule update -recursive -remote That means Git 2.23 (August 2019) or more. With git checkout, if the branch name to follow is “. is used to indicate that the name of the branch in the submodule should be the same name as the current branch in the current repository. gitmodules for update -remote.Ī special value of. The name of the branch is recorded as submodule.branch in. Note that with Git 2.10+ (Q3 2016), you can use ‘. # the latest commit from the branch is used # -remote will also fetch and ensure that Subsequent update for that submodule will have to use the -remote option: # update your submodule Git commit -m "Make submodule tracking a branch" Usually, it is ‘origin’)ĭon’t forget to record the new state of your submodule in your parent repo: cd /path/to/your/parent/repo (with ‘origin’ being the name of the upstream remote repo the submodule has been cloned from.Ī git remote -v inside that submodule will display it. Git checkout -b branch -track origin/branch Make sure your submodule is actually at the latest of that branch: cd path/to/your/submodule Make sure the parent repo knows that its submodule now tracks a branch: cd /path/to/your/parent/repo Note that if you have an existing submodule which isn’t tracking a branch yet, then (if you have git 1.8.2+): (Git 2.22, Q2 2019, has introduced git submodule set-branch -branch aBranch - ) ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |