GitHub: How to Convert a forked public repository to 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

First, duplicate the repo (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:

The only way to create a pull request is to have push access to the public repo. This is 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_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 simply 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).

--

--

--

Programmer || Undergraduate CSE student || Free lance Editor || Developer@home ||

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Step-by-Step AWS EC2 Set-up Tutorial

About Me — Nevin Katz

CardStarter Tiers — V6

Set up a Yii 2.0 Application in Windows

Event sourcing in practice with Event Store and F#

Bluetooth (BLE) advertising with Arduino ESP32 sample code (no coding) (Part 1)

Webinar Series 101 : Know Our Mentors! #MentorAnswersItAll

Introduction to Git

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Virinchi Sai

Virinchi Sai

Programmer || Undergraduate CSE student || Free lance Editor || Developer@home ||

More from Medium

Pesakit: Developer companion for Mobile API integration development and testing stage.

Work Log 2022.01.12: Stripe Integration + Oura Update

Invoice Management System on Blockchain In 2022

How is working on a Unilevel MLM plan software?