Create a public branch from a private repository

Hi everyone,

I’m a PhD researcher, new to GitHub, and I’m wondering if it would be possible to create a public branch from a private repository. I explain:

There is currently a call for opening science and research, not only for reproducibility reasons but also to guarantee the advancement of science through openness. My institute is discussing how to create “publication packages”, which are basically zipped folders containing all that relates to any journal publication: text, code, data, figures, etc.

Being an Overleaf user, I connect my projects to GitHub and cloud storage, so I have backups and can easily control the work I’m doing. I try to keep all my files organized in folders within Overleaf, including the data, SQL and R scripts, etc. My repositories are kept private but I can make them public when the paper is published.

Here is the problem: some of the data we use in my institute cannot be shared due to licencing issues. We have, for instance, contracts with companies such as the Web of Science, so we can use their database for research purposes, but we are not allowed to share the microdata (only the aggregated results). So, what I would like to do is to work with private repositories including all my data, code and outputs, but then create a branch with only the content which is possible to share and make that public.

I know I could duplicate a private repository, delete what can’t be shared and make the copy public, but that seems to be less than ideal.

Any help is appreciated and sorry if that is too dumb of a question.

It is not possible to have only some branches within a repository public. If someone can clone, they get everything.

Do it the other way around: Create a new (empty) public repository, and push only the branch(es) you want to make public to there. You can have multiple remotes (remote repositories) for a single local repository, though of course you’ll have to be careful not to push private branches to the wrong one.

See: Git - Working with Remotes

Just as a hint: Avoid adding things like ZIP archives to a Git repository, add the files directly instead. Of course nothing stops you from then creating archives from the repository, if you want to offer download bundles for people who don’t use Git.