Search code examples
gitversion-controlrepositorysubdirectory

Git: how to make a subfolder in a private repo as a public repo without splitting it out from the parent repo?


I saw there are a lot of discussions talking about splitting a subfolder of an existing repository into a separate Git repository. My questions is can I just initialize a subfolder of an existing Git repository and push it to a remote place as a new one? I don't care whether the past history of the subfolder preserved in the new repo, but I actually only want to share the subfolder to allow people to contribute into it while let the parent Git project easily track all the changes in the subfolder.

More details: I have read through some methods using Submodule, but that is not what I want from my understanding. When I checkout my parent repo or internal collaborators pull the changes of the parent repo, I expect all changes from the subfolder to be synchronized as well. Maybe subtree neither work for me, but after reading over some posts online, I am actually not sure about my judgement. I prefer to have a simple solution, like just initialize the subfolder as a new folder and push... Does it work.

Thanks for your input!


Solution

  • can I just initialize a subfolder of an existing Git repository and push it to a remote place as a new one?

    No. Git-repo is monolithic object, any|all changes of tree inside repo aren't visible to external views as independent object

    Submodule, but that is not what I want from my understanding

    You have to verify your understanding and fix it. Structuring by submodules assumes supporting link between states of parent repo and submodule, and this link reflect changes on both sides