sparse-checkout¶
Sometimes I need only a small portion of a huge git repository. Cloning (downloading) and updating whole repository in that situation is just a wast of time. Luckily git allows us to work with only the data we want from a git repository.
For example
linuxmint/cinnamon-spices-extensions
repository is used to maintain every extension made for Cinnamon Desktop Environment. Let's say we
found a bug in the horizontal-osd@berk-karaal extension and want to create a PR to fix it. Does it
mean we have to clone and pull whole other extensions in the repository? No, we will specify git to
which files we want to work with. To do that:
-
Clone repository without any file and no checkout:
-
Activate sparse checkout:
What is sparse-checkout?
Sparse checkout allows users to work with a subset of the repository files. When set, git only tracks specified files.
You can check if sparse-checkout is activated via
$ git config core.sparseCheckoutcommand. This will returntrueif it's activated.You may want to read Cone Mode Handling (default mode) and Non-Cone Problems sections.
-
Specify which files and directories to include in working tree:
More on
sparse-checkout setYou can pass multiple directories or files as arguments in this command.
Selected files are stored in
.git/info/sparse-checkoutfile. You can edit this file in.gitignoreformat.As you can see in the
.git/info/sparse-checkoutfile, git will get all the files in the root path by default (/README.mdfor example). If you want to avoid that, check outsparse-checkout init --no-coneoption. -
Checkout to the preferred branch:
This will pull files selected with sparse-checkout from given branch.
PS:
- Check out these commands:
sparse-checkout init --no-conesparse-checkout listsparse-checkout disable
- git-scm.com/docs/git-sparse-checkout