Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

How can I fork a public repository, but make my fork private? I do have the subscription to support private repositories.

like image 715
zer0stimulus Avatar asked Apr 08 '12 19:04

zer0stimulus


People also ask

Can a GitHub fork be private?

Github does not allow a forked repository to be private. This article describes a way to make a private repo that can pull new features of a public repo. The private repo will behave just as a forked repo of the public repo.

Can we create Fork of private repository?

You can fork it and it still remains private. Private collaborators may fork any private repository you've added them to without their own paid plan. Their forks do not count against your private repository quota.


2 Answers

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.git cd public-repo.git git push --mirror https://github.com/yourname/private-repo.git cd .. rm -rf public-repo.git 

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 

To pull new hotness 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 

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.git cd the-fork git remote add private_repo_yourname https://github.com/yourname/private-repo.git git checkout -b pull_request_yourname git pull private_repo_yourname master git 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).

like image 189
Martin Konicek Avatar answered Sep 25 '22 05:09

Martin Konicek


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/button enter image description here
  3. click it and put the existing github repo url There is no github option mention but it works with github repos too. enter image description here
  4. DONE
like image 33
szydan Avatar answered Sep 22 '22 05:09

szydan