Skip to content

Forking to a private repo

Alfred Nutile edited this page May 22, 2023 · 1 revision

Here are some docs from ChatGPT that I am still testing:

Yes, you're correct that on GitHub, you cannot create a private fork from a public repository. But there's a workaround for this. You can effectively create a "manual" private fork by duplicating the repository. Here's how to do it:

  1. Create a new private repository on GitHub. This will be your private "fork."

  2. Clone the public repository to your local machine:

    git clone https://github.com/original_owner/original_repo.git
  3. Navigate into the directory that was just created (it will have the same name as the repository):

    cd original_repo
  4. Remove the link to the original repository:

    git remote remove origin
  5. Link the local repository to your new private repository:

    git remote add origin https://github.com/your_username/new_repo.git
  6. Push the local repository to your private repository:

    git push -u origin main

You now have a copy of the public repository as a private repository on your GitHub.

When the public repository gets updates, you can merge them into your private repository by adding the public repository as a remote:

git remote add upstream https://github.com/original_owner/original_repo.git

Then, you can fetch the updates:

git fetch upstream

And merge them into your private repository:

git merge upstream/main

Or, if you want to rebase (apply your changes on top of the fetched changes):

git rebase upstream/main

Then, push your changes to your private repository:

git push origin main

That's it! This will allow you to have a private "fork" of a public repository and to merge updates from the public repository into your private one.