1

Let me first describe the problem. Assume that I have the following directories structure:

Repo-A
  - ...
  - sub-dir-A
    - ...

Repo-B
  - ...
  - sub-dir-B
    - ...
Repo-C
  - ...
  - sub-dir-C
    - ...
...

What I want to do is the following: I want to make Repo-A, Repo-B, and also Repo-C all private, which contains all and sub-dir-A, sub-dir-B and sub-dir-C's contents, while making sub-dir-A, sub-dir-B and sub-dir-C into another public repo. i.e.,

Repo-A
  - ...
  - sub-dir-A
    - ...

Repo-B
  - ...
  - sub-dir-B
    - ...
Repo-C
  - ...
  - sub-dir-C
    - ...


Repo-Public
  - sub-dir-A
  - sub-dir-B
  - sub-dir-C

My approach now is rather naive, I just simply create another separate public repo and copy-pasting all the sub-dir-<A, B, C, ...> into that new directory and manually update them, which is a pain.

I'm not sure whether this is doable, especially I'm familiar with working with sourcetree but not the command line for git. (But if the only option is using the command line to manipulate things around, then I can learn it for sure). I have looked into the symbolic link and things like submodule and subtree in git, but can't find a useful tutorial. They're usually talking about how to split two directories, while I want to make them integrated somehow.

pbb
  • 55
  • 6
  • 1
    git submodules are the way to go – Daniel A. White Jan 24 '22 at 02:05
  • @DanielA.White - submodules must to be avoided as much, as possible, as one of shiftiest part of Git – Lazy Badger Jan 24 '22 at 02:43
  • 1
    You **have** to search more carefully and read using brain - subtree IS the definitive answer (with small headache after successful transition) – Lazy Badger Jan 24 '22 at 02:46
  • Ok, it's my bad that I forget another important thing: I want to link **several** such sub-directory (with different parent directories) into one huge repo. I have updated my question. – pbb Jan 24 '22 at 05:57

1 Answers1

1

Copy sub-dir-<A, B, C, ...> into their own separate public repositories using git subtree split. Next time you change something in these subdirectories in repos <A, B, C, ...> do git subtree push to update one of those separate public repo.

Create a new repository <Repo-Public> and copy sub-dir-<A, B, C, ...> into it using either git submodule add (and later update using git submodule update --remote) or git subtree add (update with git subtree pull).

phd
  • 82,685
  • 13
  • 120
  • 165
  • It's quite complicated actually, is there a simpler workaround? Since I don't want multiple sub-dir-repo flying around in my github. – pbb Jan 24 '22 at 21:17
  • @PingbangHu I don't think there is a simpler way. Your task is too complex for Git which is intended to pull/push commits and branches for whole repositories, not files and directories. (G)it has problems with separate subfolders. – phd Jan 24 '22 at 23:02