Thus, we will now first create a directory for the repository, as follows. We only want to checkout or clone the frontend module subdirectory. In the project directory my_project, there are subdirectories for different modules named frontend, backend, documentation, etc. Suppose we have a project directory named my_project. We can checkout only the subdirectories we want from the project directory in the Git repository in a sparse checkout. It would suffice to only clone the project module subdirectory that a particular team is working on.Ĭloning only specific subdirectories (i.e.) a subset of the project Git repository is called sparse checkout. Thus, in such cases, one would not require to check out the entire project directory. Typically, different teams would work on different project modules in a large project. The Git repository would track this main project directory, and thus one can clone or check out the entire project directory. One would keep different project modules in separate subdirectories inside the main project directory in the project development environment. Git is used in a collaborative development environment to keep track of the changes done to files in the project directory. Clone or Checkout Subdirectory in the Repository in Git We will now illustrate this with an example. We can use the sparse-checkout feature provided by Git for such purposes.
One then can only check out or clone specific project module subdirectory. In a typical project development environment, one would segregate different project modules into different subdirectories. Git, a version control system, maintains the history of the changes done to a project directory.
#Git sparse checkout how to#
This tutorial will teach how to clone a subdirectory of a Git repository.