GitHub: Make a private repository partially public

Viewed 8550

I have built a project with html + css + javascript on GitHub for a half year. It has been in a private repository, there is only one branch.

Now I want to make this repository partially public, such that:

  1. Users can use the issues feature to ask questions or write requirements, I could respond to them, we could have discussion.

  2. Actually, users don't need to see the code. But as we are on GitHub, I may want to make a small part of files public.

  3. I don't want to lose the commit history.

Could anyone tell me what are the steps (and commands ideally) I should follow?

Do I have to re-organize my folders, for example, make a public folder and a private folder?

3 Answers

You will definitely need two repositories. But you can create a public part automatically.

For example, you can use git-exporter. It allows you to define file paths available in a public repository. This utility creates a new git repository based on an existing one with a similar commit history. Only allowed files will be included in the commit contents.

Example:

Create config.json:

{
    "forceReCreateRepo": true,
    "targetRepoPath": "my-open-source-repo",
    "sourceRepoPath": ".",
    "allowedPaths": ["build/*"],
    "ignoredPaths": ["src/*"]
}

Then run command npx gitexporter config.json.

Thus, a new repository my-open-source-repo will be created that includes only certain files while preserving the entire commit history.

Then you can push my-open-source-repo and use it as Open Source.

Like so:

cd my-open-source-repo
git remote set-url origin new.github.com/username/open-source-repo-name
git push origin master

You can also create a CI script that will update your public my-open-source-repo automatically.

Related