Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lambrospetrou/6ff20245092955dd6aec68fc37e98434 to your computer and use it in GitHub Desktop.
Save lambrospetrou/6ff20245092955dd6aec68fc37e98434 to your computer and use it in GitHub Desktop.
Git sparse checkout only specific directories of a repo
BRANCH_NAME="master"
# Clone the repository .git information only
# Docs: https://git-scm.com/docs/git-clone
#
# --no-checkout :: Do not fetch any files, only the `.git` directory.
# --sparse :: Only files at the top-level directory, at the root of the repository, will be part of the checkout.
# --branch <branch_name> :: Only fetch the information for the given branch.
# --depth 1 :: Only fetch the tip commit, HEAD of the specified branch.
# --filter=blob:none :: Do not download any blob files.
git clone --no-checkout --sparse --branch "$BRANCH_NAME" --depth 1 --filter=blob:none git@github.com:lambrospetrou/lambrospetrou.github.io.git git-sparse-checkout-test
cd git-sparse-checkout-test
# Select specific directories to checkout. In the case below this will be the directories `build-tool/` and `functions/edge`.
# Docs: https://git-scm.com/docs/git-sparse-checkout
git sparse-checkout set build-tool/ functions/edge/
# Actually checkout the above directories.
# Note: Any file in the root directory of the repository will also be part of the checkout.
git checkout "$BRANCH_NAME"
# or
git checkout HEAD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment