Search code examples
gitgit-submodulesgoogletest

Error adding a git submodule with specific branch


I am trying to add googletest as a submodule to my repo

git submodule add -b v1.13.0 https://github.com/google/googletest.git external/googletest

The specific branch v1.13.0 I have mentioned to take a stable release branch of googletest. This is not branch name of my repo.

But on doing this I am facing this error:

fatal: 'origin/v1.13.0' is not a commit and a branch 'v1.13.0' cannot be created from it
fatal: unable to checkout submodule 'external/googletest'

Can someone tell why this error is coming and what is the correct way to do what I am trying to do?


Solution

  • The parameter for git submodule add -b is expected to be a branch, not a tag. Git clones the repository, looks up branch origin/v1.13.0 and failed. You can do what you want in two steps:

    git submodule add https://github.com/google/googletest.git external/googletest
    git submodule set-branch -b v1.13.0 external/googletest
    

    See the docs.