Have you ever found yourself in a situation where you need to download an entire 10GB repository just to make a small change in a single file or add a new file to a particular folder? It can be quite the hassle and a space-consuming endeavor. However, there’s a more efficient way to handle this without cluttering your disk with unnecessary data. I’ll guide you through the process step by step.
- Copy the Clone URL
First, go to the repository on GitHub and copy the clone URL.
2. Select a Local Folder
With the URL you can go to a folder where you want to clone the specific files of the repository and digit the follow commands:
3. Navegate to the cloned empty repo
This will clone the repo but empty, go inside with the cd <FOLDER NAME> command
4. Set Sparse
Inside the repo run this other command
the sparse-checkout command just works on git version 2.25.0 so make sure you have your git version updated.
5. Select a Branch
Go to the branch you want clone the folder like develop branch, master, etc… In my case here I will use the master branch
6. Cloning the specific folder
Now it’s time to download just the folder that you want, In my case I will download the “auth” folder in the repository, this folder is a subfolder of “src”, so replace this path for one that you want from your repository.
And finally, this is the result:
You can see that I cloned just the auth folder, but in the gitHub repository exist a lot of others folders and files
And there you have it! You’ve successfully cloned just the specific folder, saving both time and disk space. Keep in mind that the GitHub repository may contain numerous other folders and files, but you’ve isolated what you need for your work. Feel free to make your changes, commit, and push as you would on any other day, all while keeping your disk tidy.