I've been looking for a way to clone only a sub directory of one of my project. Obviously I found this answer. it is well designed and the step-by-step solution explain well how to implement this. Now at the end it refers to documentation which states this:
"Sparse checkout" allows to sparsely populate working directory. It uses skip-worktree bit (see git-update-index(1)) to tell Git whether a file on working directory is worth looking at.
The problem I have is that I can't understand what this mean. And one thing that I've learn with Git is that it is a fantastic tool, but before implementing something, knowing what happens behind the scene can really help you in the long run.
So, here is the question:
How does a sparse checkout works and what is the output ?
A commit points to a tree. A tree describes a directory and it points to other trees, blobs or commits. Other trees are sub directories. Blobs are files. Commits are sub modules. Not considering sub modules,
git checkout
can be seen as "copying" all of these sub directories and files from the database(inside the invisible directory.git
) to the work area(by default the same level where.git
is). Sparse-checkout copies just some of the subdirectories or files. So sparse-checkout saves the space of the work area. The occupied space by the database isn't saved.