Skip to content

Instantly share code, notes, and snippets.

@harunhasdal
Created July 17, 2025 13:49
Show Gist options
  • Save harunhasdal/5197776db30ea20777c1b668d35ccd8a to your computer and use it in GitHub Desktop.
Save harunhasdal/5197776db30ea20777c1b668d35ccd8a to your computer and use it in GitHub Desktop.
Clone and checkout only a subfolder in a github repository
REPO_URL="github url"
REPO_NAME="local folder name defaults to repo name"
SUBFOLDER_PATH_NO_LEADING_SLASH="path to the folder with no leading slash, but ending with a slash"
git clone --depth 1 --no-checkout $REPO_URL
cd $REPO_NAME
git sparse-checkout set $SUBFOLDER_PATH_NO_LEADING_SLASH
git checkout
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment