Add submodule with specific tag not branch in one command

Viewed 3991

For a rails template I'd like to add a submodule of a specific tag to new rails apps. To keep this simple I'd like to avoid going into subdirectories and running git commands there.

git submodule add --branch v1.3.37 git@example.com:foo.git vendor/foo

Is what I would like to use, but it does not accept tags for the --branch parameter:

fatal: 'origin/v1.3.37' is not a commit and a branch 'v1.3.37 cannot be created from it Unable to checkout submodule 'vendor/foo'

Is there a simple way to add a git submodule on a specific tag?

2 Answers

You can make a workaround: just fork target repository and create a new branch from upstream tag.

git clone git@my.example.com:foo.git /tmp/foo && cd /tmp/foo
git checkout -b release-v1 v1
git push --set-upstream origin release-v1
cd ~/workspace && git submodule add --branch release-v1 git@my.example.com:foo.git vendor/foo

But later you will have to create new branches from news tags before using it as git submodule.

Related