5

I have a public repository on github and each user of my group has a fork of it. The policy is that committing directly to the main repo is forbidden and all the changes must come in as pull requests from the forks so that they can be reviewed before being merged to the main repo.

Given that sometimes we develop code that must stay private for a certain period before going public in the main repo, I would like to have the following situation:

  • Main repo public
  • Forks private
  • Be able to make pull requests from the forks to the main repo
  • Keep things easy, given that some user are git beginners

Now, on Github this is not possible because private forks are not allowed.

What strategy can I use to achieve a similar behavior?

Simone Gaiarin
  • 340
  • 2
  • 15

1 Answers1

6

I just did something similar to this. The solution what worked for me was to create a new private Repo as a bare clone of your main repo, and push the all the new changes to this private repo, and once the changes are ready to be made public, push the changes to the public repo.

I followed the steps from : Answer to this question by: Martin Konicek

  1. Duplicate the repo (details here):

  2. Create a new repo (private-repo) via the Github UI. Then:

    git clone --bare https://github.com/exampleuser/public-repo.git cd public-repo.git git push --mirror https://github.com/yourname/private-repo.git cd .. rm -rf public-repo.git


  1. Clone the private repo so you can work on it:

    git clone https://github.com/yourname/private-repo.git cd private-repo make some changes git commit git push origin master


  1. To pull new changes from the public repo:

    cd private-repo git remote add public https://github.com/exampleuser/public-repo.git git pull public master # Creates a merge commit git push origin master

The private repo now has the latest code from the public repo plus your changes.


  1. Create a pull request private repo -> public repo:

Ceating a pull request requires push access to the public repo because you need to push to a branch there (here's why).

git clone https://github.com/exampleuser/public-repo.git
cd public-repo
git remote add private_repo https://github.com/yourname/private-repo.git
git checkout -b pull_request_branch
git pull private_repo master
git push origin pull_request_branch

Now simply create a pull request via the Github UI for public-repo, as described here.

Once project you review the pull request, you can merge it.

After the first time you just have to pull from the required remote (Public or Private) and push to the (private). Once done with the changes, push the changes to (Private : to keep it up to date) and some branch on Public so a pull request to master can be created.

cb4
  • 6,689
  • 7
  • 45
  • 57
Gaurav Arya
  • 146
  • 3