Skip to main content

git submodule

Problem

I have a private Github repo with my markdown files and I want to use them with Docusaurus.

Solution

I created a brand new repo for Docusaurus project, then cloned my private repo as a submodule.

Implementation

# create docusaurus project at /lttviet.com
pnpx create-docusaurus@latest lttviet.com classic --typescript

# delete existing /docs
cd lttviet.com
rm -rf docs

# clone to /docs
git submodule add [email protected]:lttviet/thoughts.git docs

Advanced implementation

I came across this Stackoverflow question about only cloning specific files from a submodule instead of the whole repo.

# clone submodule without files
git clone --filter=blob:none --no-checkout [email protected]:lttviet/thoughts.git docs

# set up submodule
git submodule add [email protected]:lttviet/thoughts.git docs
git submodule absorbgitdirs
git -C docs config core.sparseCheckout true

# pattern to get files from submodule
echo 'guides/*.md' >> .git/modules/path/some-repo/info/sparse-checkout

# finally checkout
git submodule update --force --checkout docs