30

I'm wondering what's the best way to publically share on Github a file that's on a private repo on Github.

I would like thet every time a make a push in my private repository automatically the file is updated too.

In particular I have a .tex project: I would like to keep secret the tex files but I would like to make available to everyone the pdf file.

Note I'm aware of the existence of the gitignore option, but I don't want to use it since I want to keep track of the improvements on the tex files

Erik Pillon
  • 431
  • 1
  • 4
  • 11
  • 1
    [Here](https://stackoverflow.com/a/76283567/7991646) is a similar concept to VonC's answer, minus using submodules. Also using a GitHub Actions workflow instead of a bash script. – jrbe228 May 18 '23 at 19:01

5 Answers5

5

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.

georgegkas
  • 417
  • 6
  • 14
4

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I don't see the advantage of using submodules in this case. You need two repos (public, private) anyways. Might as well just copy (with a script) changed files (.pdf) from the private to the public repos and commit from there. That step can be scripted, too, as you said. – Marius Hofert Apr 06 '19 at 01:47
  • @MariusHofert I suppose the idea I was thinking about more than a year ago as to be able to clone a repo, and get automatically another one through the submodule reference. I did not put the binary generated file in the public repo itself, but rather as a release artifact. – VonC Apr 06 '19 at 06:32
2

Using the raw link provides a URL with a "token=", which seems to expire after a certain number of days.

Ken Butler
  • 37
  • 3
2

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
Hipster
  • 29
  • 1
0

If it's just one file, you can just use the raw link. Go to that file on GitHub and click "raw"

Just use the link in the adress bar and it should work...

Raul Chiarella
  • 518
  • 1
  • 8
  • 25