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.

4
  • 1
    git submodules are the way to go Commented Jan 24, 2022 at 2:05
  • @DanielA.White - submodules must to be avoided as much, as possible, as one of shiftiest part of Git Commented Jan 24, 2022 at 2:43
  • 1
    You have to search more carefully and read using brain - subtree IS the definitive answer (with small headache after successful transition) Commented Jan 24, 2022 at 2: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. Commented Jan 24, 2022 at 5:57

1 Answer 1

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).

Sign up to request clarification or add additional context in comments.

2 Comments

It's quite complicated actually, is there a simpler workaround? Since I don't want multiple sub-dir-repo flying around in my github.
@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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.