Is there a way to download only a subdirectory from git?

Is there a way to download only this subdirectory from the git repository? Let's say I want to extract only the nyancat directory from https://github.com/djdeath/toys.git .

I could either clone the entire repository and ignore the files that I don't want, or go to https://github.com/djdeath/toys/tree/master/nyancat and download the corresponding files one at a time. I think there should be an easier way.

Note. I do not ask if it is possible to clone a directory, this was before doing it and, apparently, is impossible. I'm just interested in getting files fast and don't need to commit, or am using git again.

+4
source share
2 answers

The git-archive command will do almost what you want, but it should work with an already cloned repo, therefore, you have SSH access to the host, you can do:

 cd /path/to/destination ssh user@host "cd /path/to/repo && git archive HEAD dir/you/want" | tar xf - 

Or with compression for network transport:

 cd /path/to/destination ssh user@host "cd /path/to/repo && git archive HEAD dir/you/want | gzip" | tar xzf - 
+2
source

Hey i just wrote a script

Using

  python get_git_sub_dir.py path/to/sub/dir <RECURSIVE> 
0
source

Source: https://habr.com/ru/post/1444190/


All Articles