6

I had forked a MapBox-ios-sdk and make some changes to it. A newer release of the sdk is here and I merged my the changes into my fork. MapBox-ios-sdk also incorporate SMCalloutView which is a submodule within MapBox-ios-sdk. However the version of the official sdk uses a newer, updated SMCalloutView that's not in my fork.

How do I get it to update

I update my sdk with instructions from here. However this does not update SMCalloutView. I also tried git submodule update --recursive at the level of the MapBox-ios-sdk and nothing happens. As it turns out it's because SMCallOutView is in "no branch". Why is it at "no branch"? How do I bring all the submodule out of the state of "no branch"? If it's at "no branch" then I'd never know which submodule or submodule of the submodule (or even more nested) that needs update.

3
  • Submodules are usually at a specific commit, rather than at the tip of a branch, hence the "(no branch)". Updating sub-modules can be confusing - it depends on whether you are doing the updating, and need to commit to the super project, or whether you pulled a super project update and need to ensure that the submoules have synced up (updated). Commented Jun 19, 2013 at 16:41
  • It sounds like my case is the last example but I'm not sure what's the super project you're referring to. I am using a open source github project as a submodule of my own project. And I want to pull the latest of the open src project, including any updates to the submodule it uses (tags to) to its own, into my project.
    – huggie
    Commented Jun 19, 2013 at 17:00
  • Is there any alternative to submodule? This thing is driving me nuts. But the open source project I use relies on submodule, though moving to CocoaPods (I'm on iOS)
    – huggie
    Commented Jun 19, 2013 at 17:02

1 Answer 1

21

With git 1.8.2+ (March 2013), you can define a submodule which will reflect the latest commit of a given branch.
See "git submodule tracking latest".

It means this would be enough to update a submodule to the latest of a branch:

# --remote will also fetch and ensure that
# the latest commit from the branch is used
git submodule update --remote

See git repo commit 06b1ab for more on the --remote option.


To recap:

  • For a new submodule (which must follow a branch):

    git submodule add -b [branch] [URL] [DirectoryName]
    
  • For an existing submodule that you now want it to follow a branch:
    See also git repo commit b92892, for transforming a git submodule into one which follows a branch.
    All you need to do is:

    git config -f .gitmodules submodule.<path>.branch <branch>
    

    See more at "Git submodules: Specify a branch/tag"

3
  • 1
    Great! Now I just need to update git. This functionality came so surprisingly late. :D
    – huggie
    Commented Jun 20, 2013 at 2:36
  • A note to myself: git submodule add -b [branch] [URL] [DirectoryName]
    – huggie
    Commented Nov 15, 2013 at 3:30
  • @huggie I have included your note in the answer for more visibility, as well as added more information on how to transform an existing submodule.
    – VonC
    Commented Nov 15, 2013 at 6:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.