1

i have a private project in a private repo and it's very convenient to keep it as a single project. this way it's easy to work on it using IDE without any special commands.

but i also want to publish some part of it on github and update the public version sometimes. how can i make one subdirectory of repo A a top-level dir of repo B and still have all the standard commands apply to the whole repo A?

piotrek
  • 13,982
  • 13
  • 79
  • 165
  • See if [git subtree](https://www.atlassian.com/blog/git/alternatives-to-git-submodule-git-subtree) is what you're looking after. – Lasse V. Karlsen Aug 30 '17 at 14:21
  • I am using ``git subrepo``. The alternatives are ``git subtree`` and ``git submodule``, but my research shows that ``subrepo`` is easiest to use at this point. – Muposat Aug 30 '17 at 14:26
  • Possible duplicate of [Detach (move) subdirectory into separate Git repository](https://stackoverflow.com/questions/359424/detach-move-subdirectory-into-separate-git-repository) – phd Aug 30 '17 at 16:11
  • @phd nope, i don't want to remove anything. i want to copy a subset – piotrek Aug 30 '17 at 16:13
  • Bu the answers there — especially `git subtree` — apply, you just don't remove original directory. – phd Aug 30 '17 at 16:21

1 Answers1

0

Probably submodules/subtrees is the best way to do it, but just to provide a (somewhat convoluted) alternative :

  • Extract the subfolderB of repoA to a new, independent repoB via git filter-branch --subdirectory-filter (note that filter-branch rewrites the repo, so you should do it on a separate copy of repoA)
  • Keep working on repoA as a primary repo
  • Add repoA as a remote of repoB via git remote add repoA ...
  • Occasional changes in repoA can be cherry-picked to repoB via git fetch repoA; git cherry-pick .... Git can manage this even if file structures of two repos do not match (everything should be fine as long as the commits in repoA that you want to backport to repoB are standalone in subfolderB)
jakub.g
  • 38,512
  • 12
  • 92
  • 130