Bash Shell Script to Clone Next.js 15, DrizzleORM, or Any Documentation Locally as Markdown Files
Learn how to quickly clone only the documentation folder from GitHub repositories using sparse checkout. This guide provides ready-to-use scripts for Next.js 15 and DrizzleORM, along with instructions to adapt them for other frameworks.
AI
AG
Ala GARBAA 🚀 Full-Stack & DevOps Engineer
Cloning Documentation Repositories
1. Clone Next.js 15 Documentation
Run the following command to execute the script:
chmod +x clone-next-js-docs.sh && bash clone-next-js-docs.sh
Script for Next.js 15
This script automates cloning the Next.js documentation from the canary branch.
#!/bin/bash
#######
REPO_ORG="vercel"
REPO_NAME="next.js"
BRANCH="canary"
DOCS_REMOTE_RELATIVE_PATH="docs"
# check the repo on github: https://github.com/vercel/next.js
LOCAL_TARGET_DIR="_docs/next-js-15"
#######
echo
echo "REPO_ORG='$REPO_ORG'"
echo "REPO_NAME='$REPO_NAME'"
echo "BRANCH='$BRANCH'"
echo "DOCS_REMOTE_RELATIVE_PATH='$DOCS_REMOTE_RELATIVE_PATH'"
echo "LOCAL_TARGET_DIR='$LOCAL_TARGET_DIR'"
echo
echo "Remove directory :'$LOCAL_TARGET_DIR'"
rm -fr $LOCAL_TARGET_DIR
echo "Make directory :'$LOCAL_TARGET_DIR'"
mkdir -p $LOCAL_TARGET_DIR
echo "Change directory :'$LOCAL_TARGET_DIR'"
cd $LOCAL_TARGET_DIR
echo "Clone the repository with sparse-checkout enabled :'git clone --depth 1 --filter=blob:none --sparse --branch $BRANCH https://github.com/$REPO_ORG/$REPO_NAME.git'"
# Clone the repository with sparse-checkout enabled:
echo
git clone --depth 1 --filter=blob:none --sparse --branch $BRANCH https://github.com/$REPO_ORG/$REPO_NAME.git
echo
echo "Enter the $REPO_NAME in the cloned directory :'$(pwd)'"
# Enter the cloned directory:
cd $REPO_NAME
echo "Configure sparse checkout to include only the docs folder :'git sparse-checkout set $DOCS_REMOTE_RELATIVE_PATH'"
# Configure sparse checkout to include only the docs folder:
git sparse-checkout set $DOCS_REMOTE_RELATIVE_PATH
echo "Move the docs folder contents to your current directory and remove the rest :'mv $DOCS_REMOTE_RELATIVE_PATH/* ..'"
# (Optional) Move the docs folder contents to your current directory and remove the rest:
mv $DOCS_REMOTE_RELATIVE_PATH/* ..
echo "Go up one level :'cd ..'"
cd ..
echo "Remove the rest :'rm -rf $REPO_NAME'"
rm -rf $REPO_NAME
# This way, you end up with only the docs folder from the canary branch in your desired location.
echo
echo "Enjoy!"
echo
2. Clone DrizzleORM Documentation
To use the script with DrizzleORM, replace the repository details and documentation folder path.
#!/bin/bash
#######
REPO_ORG="drizzle-team"
REPO_NAME="drizzle-orm-docs"
BRANCH="main"
DOCS_REMOTE_RELATIVE_PATH="src/content/docs"
# check the repo on github: https://github.com/drizzle-team/drizzle-orm-docs/
LOCAL_TARGET_DIR="_docs/drizzle-team-0.40"
#######
echo
echo "REPO_ORG='$REPO_ORG'"
echo "REPO_NAME='$REPO_NAME'"
echo "BRANCH='$BRANCH'"
echo "DOCS_REMOTE_RELATIVE_PATH='$DOCS_REMOTE_RELATIVE_PATH'"
echo "LOCAL_TARGET_DIR='$LOCAL_TARGET_DIR'"
echo
echo "Remove directory :'$LOCAL_TARGET_DIR'"
rm -fr $LOCAL_TARGET_DIR
echo "Make directory :'$LOCAL_TARGET_DIR'"
mkdir -p $LOCAL_TARGET_DIR
echo "Change directory :'$LOCAL_TARGET_DIR'"
cd $LOCAL_TARGET_DIR
echo "Clone the repository with sparse-checkout enabled :'git clone --depth 1 --filter=blob:none --sparse --branch $BRANCH https://github.com/$REPO_ORG/$REPO_NAME.git'"
# Clone the repository with sparse-checkout enabled:
echo
git clone --depth 1 --filter=blob:none --sparse --branch $BRANCH https://github.com/$REPO_ORG/$REPO_NAME.git
echo
echo "Enter the $REPO_NAME in the cloned directory :'$(pwd)'"
# Enter the cloned directory:
cd $REPO_NAME
echo "Configure sparse checkout to include only the docs folder :'git sparse-checkout set $DOCS_REMOTE_RELATIVE_PATH'"
# Configure sparse checkout to include only the docs folder:
git sparse-checkout set $DOCS_REMOTE_RELATIVE_PATH
echo "Move the docs folder contents to your current directory and remove the rest :'mv $DOCS_REMOTE_RELATIVE_PATH/* ..'"
# (Optional) Move the docs folder contents to your current directory and remove the rest:
mv $DOCS_REMOTE_RELATIVE_PATH/* ..
echo "Go up one level :'cd ..'"
cd ..
echo "Remove the rest :'rm -rf $REPO_NAME'"
rm -rf $REPO_NAME
# This way, you end up with only the docs folder from the canary branch in your desired location.
echo
echo "Enjoy!"
echo
3. Explanation of the Script
Below is a breakdown of what each command in the script does:
#!/bin/bash
- Specifies that this script should be run in the Bash shell.
REPO_ORG="vercel"
- Defines the GitHub organization name.
REPO_NAME="next.js"
- Specifies the repository to be cloned.
BRANCH="canary"
- Sets the branch to fetch the documentation from.
DOCS_REMOTE_RELATIVE_PATH="docs"
- Defines the folder path within the repository that contains the documentation.
LOCAL_TARGET_DIR="_docs/next-js-15"
- Sets the local directory where the documentation will be stored.
rm -fr $LOCAL_TARGET_DIR
- Removes any existing directory with the same name to ensure a clean clone.
mkdir -p $LOCAL_TARGET_DIR
- Creates the target directory if it doesn’t exist.
cd $LOCAL_TARGET_DIR
- Navigates into the target directory.
git clone --depth 1 --filter=blob:none --sparse --branch $BRANCH https://github.com/$REPO_ORG/$REPO_NAME.git
- Clones the repository with minimal depth, filtering out unnecessary files.
cd $REPO_NAME
- Moves into the cloned repository directory.
git sparse-checkout set $DOCS_REMOTE_RELATIVE_PATH
- Configures sparse checkout to include only the documentation folder.
mv $DOCS_REMOTE_RELATIVE_PATH/* ..
- Moves the contents of the documentation folder to the main target directory.
cd ..
- Moves up one directory level.
rm -rf $REPO_NAME
- Removes the cloned repository, leaving only the documentation files.
echo "Documentation successfully cloned!"
- Prints a success message.