0

I'm trying to utilize git subtree to add another repo into my existing repo. Problem is I don't want all the files from the repo. I only want to clone the files within a specific folder.

So for example, my main repo is like this

/
 /public
 /server
 /books

And the other repo (which I want to clone into the above is)

   /
    /booksrepo/info.json
              /info2.json
              /info3.json
    settings.json
    config.json

If I clone the whole repo, I get everything including the config/settings files. Instead I only want to target the booksrepo folder. So in the end, I want it to look like

/
 /public
 /server
 /books/info.json
       /info2.json
       /info3.json

This tutorial https://gist.github.com/SKempin/b7857a6ff6bddb05717cc17a44091202 doesn't seem to mention about picking from only a subfolder. Is there a way to achieve this?

Thanks

omega
  • 40,311
  • 81
  • 251
  • 474
  • I don't think there is a simpler way then detach `/booksrepo/` from the other repo into a separate repository. Like [this](https://stackoverflow.com/a/70833606/7976758). In the other repo: `git subtree push -P booksrepo separate_repo` and then `git subtree add -P books separate_repo` in the first repo. – phd Jan 16 '23 at 17:00
  • In addition to my previous comment: Git cannot easily [clone/fetch/pull a subdirectory](https://stackoverflow.com/search?q=%5Bgit%5D+clone+subdirectory), it can only fetch full commits or chains of commits. But `git subtree` can push a subdirectory. – phd Jan 17 '23 at 11:36
  • what about pull a subdirectory only? @phd – omega Jan 18 '23 at 22:13
  • Did you read [this comment](https://stackoverflow.com/questions/75137229/how-to-clone-only-a-specific-folder-when-doing-git-subtree?noredirect=1#comment132607256_75137229)? Git cannot do that. – phd Jan 18 '23 at 23:33

0 Answers0