GitHub doesn't allow making a private fork of a public repository. Their rule is: once public, always public. The usual way to get around this is to clone the repository to your computer and then push it to a new private repository. But there's an easier way to do this directly in GitHub's interface.

Creating a Private Copy Using Import Repository

You can create a private copy without touching the terminal:

  1. Go to the public GitHub project and copy its URL
  2. Click the plus button in the top-right corner of GitHub and select 'Import repository'
  3. Paste the URL, give your new repository a name, and set it to Private
  4. Click 'Begin Import' and GitHub will copy everything, including all commit history

When the import finishes, you'll have an exact copy of the original project with all its code and history, but it's private instead of public.

Keeping Your Private Copy Updated

Unlike a traditional GitHub fork, you can't use the sync button you might be familiar with in the GitHub UI. But don't worry - you can still keep your private repo in sync with the original. You just need to add the source repo as a remote:

  1. Copy the URL of the original repository
  2. In your local repository folder, run git remote add upstream <original-repo-url>
  3. Get the latest code by running git fetch upstream
  4. Pull in the changes with git merge upstream/main

This lets you grab changes from the original project while keeping your work private. Just remember that you'll need to run git fetch upstream first whenever you want to get the latest updates.

Cherry-Picking Specific Commits

Sometimes you don't want all the changes from the original repo - just certain ones. You can cherry-pick exactly what you need:

  1. Find the commit ID you want from the original repository
  2. Run git fetch upstream to get the latest code
  3. Grab just that one commit with git cherry-pick <commit-id>
  4. Push it to your repo with git push

This way you can grab just the bits you want without taking everything.

Starting Fresh with a Clean History

When starting a new project from a template, you might want to clean up the commit history. Check out my bash script that I include in my SAAS open source template.

Before running the script, you might want to change the initial commit message. Just edit line 24:

git commit -m "Starting from fresh with Steady Start template"

After running this script, your repository will have just one commit. Remember that once you do this, you can't use git merge or git cherry-pick with the original repository anymore.

Conclusion

These methods give you several ways to work with public code while keeping your changes private. Whether you need a quick private copy, want to stay in sync with the original project, or start fresh with a clean history, these tricks make it much easier than the traditional approach.

The entire episode is available on YouTube