Ubuntu – How to clone only some directories from a git repository


For example, I want to download PCL 3d_rec_framework.

This is the git repository of PCL: https://github.com/PointCloudLibrary/pcl.git

How can I download this directory?


I tried this, but it didn't work:

sam@sam:~/code/pcl_standalone$ git clone https://github.com/PointCloudLibrary/pcl/tree/master/apps/3d_rec_framework
Cloning into '3d_rec_framework'...
error: The requested URL returned error: 403 while accessing https://github.com/PointCloudLibrary/pcl/tree/master/apps/3d_rec_framework/info/refs
fatal: HTTP request failed

I don't want to download git of PCL and remove all other directories that I don't want.

How do I download just a single directory?

Best Answer

You cannot. With git, you clone the entire repository, and the full history of the repository.

There are some workaround solutions to be able to get a single file out of a git archive, listed on a Stack Exchange answer for the same question, but you will still have to download the entire repository to get that single file or directory you want.