Share publically a part of a private repo on Github

Github does not provide such functionality. Github repositories are either public or private, both not both. However, if the part you want to share is small enough (let' say 4-5 files) you can create a public gist. Unfortunately, there is no way to update the gist automatically.


You can create a public Github repository automatically based on your existing private repository.

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": ["*.pdf"],
    "ignoredPaths": ["*.tex"]
}

Then run command npx gitexporter config.json.

New repository my-open-source-repo includes only "*.pdf" files.

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 github.com/orgname/repo-name.git
git push origin master

I would like to keep secret the tex files but I would like to make available to everyone the pdf file.

You can dedicate a public repo (with a simple README in it) in order to upload and associate to said public repo an artifact (your pdf) as a GitHUb release.

Add that public repo as a submodule of your private repo: that will create a subfolder with the README in it, explaining where to find the pdf (in the release section of the public repo)

You can then, from your own private repo:

  • update the README (just for creating a new commit)
  • tag the README submodule repo (to create a tag that you will associate your release with)
  • upload your pdf to the public repo release, associated to the tag created.

All those steps can be scripted, using the GitHub API: here is an example (focused on the release upload part) in bash shell.