Home > Mobile >  Clone a subfolder from git repo without the repo structure
Clone a subfolder from git repo without the repo structure

Time:12-21

I would like to clone a subfolder of this project https://github.com/veista/smartthings namely smartthings/custom_components/smartthings however all the answers of related questions keep the repo structure: my-dir/smartthings/custom_components/smartthings and I would like the following result: my-dir/smartthings(the subfolder, not the repo root)

Is it possible?

CodePudding user response:

You can:

That is:

cd local/cloned/repo
git filter-repo --path custom_components/smartthings/ --path-rename custom_components/smartthings/:/
git remote set-url origin https://github.com/<me>/<newRepo>
git push

CodePudding user response:

If you're on some soda-straw connection or paying by the byte or something, you can also use the filtering support the main Git hosting services support and Git's core commands,

git clone -n --filter=tree:0 https://github.com/veista/smartthings
cd smartthings
git read-tree -um @:custom_components/smartthings

and to check out another commit you do git reset --soft $thatcommit; git read-tree -um @:custom_components/smartthings. Everything else can be worked around in similar fashion.

This is really not how Git's built to operate. In any real use it is vastly more efficient to just fetch the damn repo. This repo you only want a piece of is 508KB including the checkout; it's a 188KB download. The page load for checking answers to your question exceeds the sum total of all the data traffic you could save with this, to say nothing of the human time and effort spent on the task.

  •  Tags:  
  • git
  • Related