GitHub: How to make a fork of public repository private? GitHub: How to make a fork of public repository private? git git

GitHub: How to make a fork of public repository private?


The answers are correct but don't mention how to sync code between the public repo and the fork.

Here is the full workflow (we've done this before open sourcing React Native):


First, duplicate the repo as others said (details here):

Create a new repo (let's call it private-repo) via the Github UI. Then:

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

Clone the private repo so you can work on it:

git clone https://github.com/yourname/private-repo.gitcd private-repomake some changesgit commitgit push origin master

To pull new hotness from the public repo:

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

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


Finally, to create a pull request private repo -> public repo:

Use the GitHub UI to create a fork of the public repo (the small "Fork" button at the top right of the public repo page). Then:

git clone https://github.com/yourname/the-fork.gitcd the-forkgit remote add private_repo_yourname https://github.com/yourname/private-repo.gitgit checkout -b pull_request_yournamegit pull private_repo_yourname mastergit push origin pull_request_yourname

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

Once project owners review your pull request, they can merge it.

Of course the whole process can be repeated (just leave out the steps where you add remotes).


There is one more option now ( January-2015 )

  1. Create a new private repo
  2. On the empty repo screen there is an "import" option/buttonenter image description here
  3. click it and put the existing github repo urlThere is no github option mention but it works with github repos too.enter image description here
  4. DONE


The current answers are a bit out of date so, for clarity:

The short answer is:

  1. Do a bare clone of the public repo.
  2. Create a new private one.
  3. Do a mirror push to the new private one.

This is documented on GitHub: duplicating-a-repository