Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cloning subtree/subdirectory of git repo

I have a git repo on Github, looks like so:

.git/
assets/
  tools/
    a.sh
    b.sh
    c.sh

of course the .git folder is not in version control, but you get the idea. And I want to copy the tools/*.sh to a local directory, at this path:

./scripts/git/tools

My current directory is a git repo that shares a totally different history than the remote git repo, I just want to copy some files from the remote, I don't want to merge anything.

I figure I could do something like this:

git clone --path assets/tools/*.sh "$remote_repo"  ./scripts/git/tools

but that command is not real, is there some command I can use to do this?

the only other way I can think of doing it, is cloning the whole repo to some temp directory and then copying the files over, but that's not as much fun.

like image 486
Alexander Mills Avatar asked Jan 02 '23 04:01

Alexander Mills


1 Answers

For Github repos, you can clone any sub-directories of any repo using the tool github-clone

Install it like this:

pip install github-clone

Then use it like this:

ghclone https://github.com/HR/Crypter/tree/dev/app
like image 193
CryptoGeek Avatar answered Jan 05 '23 11:01

CryptoGeek