Setup
git init <arbitrary folder name>
cd <arbitrary folder name>
Add the base github repo
git remote add origin <github url>
ex
git remote add origin "https://github.com/elastic/elasticsearch.git"
Enable sparse checkout
git config core.sparseCheckout true
Grab folder path ex
https://github.com/elastic/elasticsearch/tree/main/docs/reference/query-dsl
->
docs/reference/query-dsl/*
Echo that path into .git/info/sparse-checkout
ex
echo "docs/reference/query-dsl/*" >> .git/info/sparse-checkout
Download the latest commit's files
git fetch --depth=1 origin main
git checkout main