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.

Community
  • 1
  • 1
huggie
  • 17,587
  • 27
  • 82
  • 139
  • 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). – Philip Oakley Jun 19 '13 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 Jun 19 '13 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 Jun 19 '13 at 17:02

1 Answers1

20

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"

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Great! Now I just need to update git. This functionality came so surprisingly late. :D – huggie Jun 20 '13 at 02:36
  • A note to myself: `git submodule add -b [branch] [URL] [DirectoryName]` – huggie Nov 15 '13 at 03: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 Nov 15 '13 at 06:34