Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Last active April 25, 2024 18:18
Show Gist options
  • Save drmalex07/eb5696a2b4d88c6effbe6096d4bb922a to your computer and use it in GitHub Desktop.
Save drmalex07/eb5696a2b4d88c6effbe6096d4bb922a to your computer and use it in GitHub Desktop.
Checkout subtree of a Git repository. #git #git-sparse-checkout #git-checkout

README - Checkout subtree of a Git subdirectory

See also: https://unix.stackexchange.com/questions/233327/is-it-possible-to-clone-only-part-of-a-git-project

Clone with a specific history depth (--depth) and start at the root of the repository (--sparse). You can also filter-out BLOB files. For example:

git clone --sparse --depth 1 --filter blob:none --branch master https://github.com/NowhereLand/helloworld

Change directory into the newly-cloned repository and enable sparse-checkout mechanism (to fetch parts of the subtree in steps of increasing depth)

cd helloworld
git sparse-checkout init --cone

Checkout a subtree, say at /src/main/resources:

git sparse-checkout set src/main/resources/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment