Reputation: 1483
git clone my-new-repo-url
mkdir deps
cd deps
git submodule add -b 6.2.0 https://github.com/leethomason/tinyxml2.git
yields
fatal: 'origin/6.2.0' is not a commit and a branch '6.2.0' cannot be created from it
Unable to checkout submodule 'deps/tinyxml2'
does not populate .gitmodules, but creates a folder .git/modules/deps/tinyxml2
and adds a repo in deps/tinyxml2
I thought I did this way before, and it would populate .gitmodules with
[submodule "deps/tinyxml2"]
path = deps/tinyxml2
url = https://github.com/leethomason/tinyxml2.git
branch = 6.2.0
but it's not working now what's up?
Upvotes: 8
Views: 14180
Reputation: 1483
A branch and a release tag are not the same thing. A branch may continue to be developed and change over time. Having the flag in .gitmodules branch = something
means the submodule will track that branch when asked to update.
git submodule add https://github.com/leethomason/tinyxml2.git
populates .gitmodules with
[submodule "deps/tinyxml2"]
path = deps/tinyxml2
url = https://github.com/leethomason/tinyxml2.git
Then manually checking out the desired tag in the submodule with
cd deps/tinyxml2
git checkout 6.2.0
Add/commit/push with
git commit -am "adding and commiting all in one command"
git push
Adds the submodule to the repo, and in the browser we can see
where c1424ee4
is the specific commit where that release-tag was generated
Now doing a fresh clone into another folder
git clone my-new-repo-url
git submodule update --init --recursive
Has the submodule checked out at the same release tag 6.2.0 (commit c1424ee4
)
Upvotes: 13