3

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?

1 Answer 1

6

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 init in them, and commit.

If you do want to preserve history, you'll want to do something like this:

git clone original-project project1
cd project1
git filter-branch --prune-empty --subdirectory-filter subdir1 -- --all

once per subproject. The filter-branch command rewrites history, leaving only the given subdirectory as the top level. This is obviously potentially destructive (though it leaves copies of refs in refs/originals/*) so it's pretty important to do it in a separate clone!

In either case, you'll then go create your superproject:

mkdir superproject
cd superproject
git init
git submodule add <URL of central project1 repo>
git submodule add <URL of central project2 repo>
git submodule add <URL of central project3 repo>
git commit

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.

1
  • +1. I was going to link to this guide but you said everything that needs to be said!
    – Tekkub
    Jun 9, 2011 at 3:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.