Skip to content

Adding git based source material as a git submodule

Adam Plaice edited this page Apr 23, 2023 · 1 revision

If you are creating a deck and your cards are based on source material that is version controlled with git, you can add the source material as a submodule pegged at a specific commit. If you're not interested in older commits, you can even set it up to not fetch the whole history. As an example with the Anki source code) (I would have chosen the Anki manual as an example here, but it doesn't utilize git tags and I want to demonstrate cloning at a specific tag):

  1. Change directories into your deck project directory: cd ~/anki-collab-decks/anki

  2. Add the source material git repo as a submodule. --depth 1 creates a shallow clone (most recent commit): git submodule add --depth 1 https://github.com/ankitects/anki

  3. change directories in the new source material directory: cd anki

4a. fetch only commit that you want by tag name (-n tells it to get no tags instead of all of them, this flag gets overwritten by the refspec): git fetch --depth 1 -n origin 2.1.61:refs/tags/2.1.61

4b. OR if the source material repo doesn't use tags, you can reference a commit by the hash (must be the full hash at the time of this writing): git fetch --depth 1 -n origin 55f4ccdcbedcbc6be23c6b309db52e87766d63cb

  1. checkout the submodule at the commit: git checkout 2.1.61 or git checkout 55f4ccdcbedcbc6be23c6b309db52e87766d63cb

  2. go to your deck repo: cd ..

  3. commit the source material submodule to your deck repo git add . && git commit

Your deck repo will now also contain your version-controlled source material

Clone this wiki locally