I’m currently open sourcing a project that we’ve been developing on our own personal, private git server. We want to open source part of this project on GitHub as there are still features in development that need to be ironed out.
In particular, suppose I have the following directories in my git repo:
- subdir 1 (public)
- subdir 2 (public)
- subdir 3 (private)
We would like to make dirs 1 and 2 public, while keeping dir 3 private. Is there a good way to do this?
My best guess is that you want to use submodules. You can have your top level directory simply contain those three submodules. Two will be made public, one not.
The parent project only knows the desired commit SHA1 of the submodule, so it won’t contain any actual information about the private project.
If you don’t want to preserve history, you can simply copy those three directories into new places, run
git initin them, and commit.If you do want to preserve history, you’ll want to do something like this:
once per subproject. The
filter-branchcommand rewrites history, leaving only the given subdirectory as the top level. This is obviously potentially destructive (though it leaves copies of refs inrefs/originals/*) so it’s pretty important to do it in a separate clone!In either case, you’ll then go create your superproject:
It’s important to use the central URLs; when people clone your superproject and run
git submodule update --init, it will clone the submodules from those URLs.