Cloning only a subdirectory with git [duplicate] Cloning only a subdirectory with git [duplicate] git git

Cloning only a subdirectory with git [duplicate]


Suppose your project is in a dir called project, and you want only those commits which touch project/dirB.

Then:

git clone project/ subproject/cd subprojectgit filter-branch --prune-empty --subdirectory-filter dirB HEAD 

subproject will now contain the git history which touches dirB.


Cf https://www.kernel.org/pub/software/scm/git/docs/git-archive.html

With a shell command :

git archive --remote=<repo_url> <branch> <path> | tar xvf -


I would like to share a workaround. You can clone the entire repo, and then create a symulink for subdirectory:

mkdir <repo_dir>cd <repo_dir>git clone <repo_url>ln -s <sub_dir> <your_location_where_you_want_to_checkout_sub_dir>

Again, this is not a solution - just a workaround. You will still clone the whole repo, and you can pull the changes only from . However, this was useful in some case of mine.