Search code examples
gitsparse-checkout

Cloning only a subdirectory with Git


I have a Git repository that includes subdirectories. Example dirA/dirB.

Is there a way to do a git clone on a Unix server to pull only files from a subdirectory (dirB)?

Is there some other Git command other than clone that will do this?

How do I Git a specific file?


Solution

  • If you want to clone only parts of your repository, you should look at git submodules.

    The subdirectory is managed by a specific git repository and is referenced in the main repository as a submodule.

    When you clone the main repository, the submodules are not automatically cloned.