Sometimes, we are only interested in a single folder from a repository. When we download a single folder, it allows us to work fast and not have to carry the baggage that sometimes comes with downloading the entire repository.
For example, a UI engineer might only want the UI folder from the entire micro-service repo.
We’ll use one of the public repos for this example. Here is the link to it.
mkdir Coding cd Coding/ git init git remote add origin -f https://github.com/anjanashankar9/Coding.git vim .git/info/sparse-checkout # Add leetcode to the file git config core.sparseCheckout true git pull origin master ls
Note: In the
ito open the file and write
leetcodeto edit it. To exit the
vim, press escape and type
:xto save and exit the file.
Once we set the config to sparse-checkout, we can do a pull.
Run the above commands in the terminal below:
We can think of the sparse-checkout file as the reverse of the
This is an extremely handy trick for large repos, especially when we only have to work with a small number of files or folders from it.
View all Courses