5

I found this q/a: How can I have linked dependencies in a git repo?

on how to add a repo as a submodule, but I'm not sure how one can add a specific release as a submodule. Is that possible? The solution from the other post is:

git submodule add git://github.com/example/some_lib.git lib/some_lib

Ive gotten checkout a certain branch to work but not a release. Is there a way of doing this in 1 step. Otherwise I could just add then revert to a tag right?

Community
  • 1
  • 1
Bren
  • 3,516
  • 11
  • 41
  • 73
  • Will you explain what you think happens when you do `git checkout --recurse-submodules` or any of the other ways to do it, and how that differs from what you want? It's really not clear what you're trying to do, I'm not sure whether you're having trouble with checkout or add, or both, for instance. – jthill Apr 28 '17 at 03:48

1 Answers1

7

A submodule always result into a specific SHA1 being recorded by the parent repo: it is called a gitlink (special entry in the index of the parent repo).

So simply add the repo as a submodule (it does not matter what branch/commit end up being actually recorded).

cd /path/to/parent/repo
git submodule add /url/of/submodule/repo

Then go into the submodule folder and checkout the exact sHA1 or tag you want (the one corresponding to a release)

cd mysubmodule
git checkout <SHA1_of_a_release>

Go back to the parent repo, add, commit and push: you will record the new submodule state (which is to say you will record the SHA1 you want)

 cd ..
 git add .
 git commit -m "set submodule to a release SHA1"
 git push

Whenever you will clone --recursive your parent repo, your submodule willbe checked out to that release SHA1 again.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250