How to update git submodule who's history was rewritten

Say I have a git submodule already setup, and the upstream commit history has rewritten (for example a rebase squash was preformed).

Say the commit my submodule head is set to no longer exits. So I want to set the head hash submodule’s repo’s head. How do I do that?

  • How do I clone into a non-empty directory?
  • Windows-specific Git configuration settings; where are they set?
  • How to do a pre-checkout with Git
  • Are there any real differences between using “fixup!” or “squash!”?
  • Deploying a git submodule with Capistrano 3
  • Git > dyld: lazy symbol binding failed: Symbol not found: _iconv_open
  • How can I pull down a commit from Github (Enterprise) that I don't have locally?
  • Changing a Github pull request
  • git, SSH_ASKPASS on windows
  • Replay the last N git commits on a different branch
  • How source control management interworking can be achieved?
  • concept of bare shared repository in git
  • One Solution collect form web for “How to update git submodule who's history was rewritten”

    You can simply go in the submodule, do a git fetch, and checkout the HEAD you need.

    cd mysubmodule
    git fetch
    git checkout origin/abranch

    Then you go back to the parent repo, add and commit that new submodule SHA1 entry.

    Note that you also can convert a submodule in order to follow the latest commits of a branch.
    In that case, a simple:

    git submodule update --remote

    would be enough.

    Git Baby is a git and github fan, let's start git clone.