Skip to content

Instantly share code, notes, and snippets.

@devinschumacher
Last active April 25, 2025 06:59
Show Gist options
  • Save devinschumacher/c0d45bc626999f19df5429c5cd549a8c to your computer and use it in GitHub Desktop.
Save devinschumacher/c0d45bc626999f19df5429c5cd549a8c to your computer and use it in GitHub Desktop.
Github Private Forks: How to privately fork a repository
title description tags
How to Create a Private “Fork” of a Public GitHub Repo
Step-by-step guide to clone a public repo into a private repository in your organization while still pulling in upstream changes.
git
github
private-fork
cli

How to Create a Private “Fork” of a Public GitHub Repo

1. Clone the original repository locally

git clone https://github.com/<ORIGINAL_OWNER>/<REPO_NAME>.git

Rename repo to whatever you want:

mv <REPO_NAME> <NEW_NAME>

2. Create a local “fork” branch

git checkout -b fork

3. Create an empty private repo in your org

  • Github.com → New → Repository (Do not initialize with a README, license, or .gitignore. + leave Initialize this repository unchecked)

4. Re-assign remotes

Rename the existing origin (public repo) to upstream and add your private repo as origin:

git remote rename origin upstream
git remote add origin [email protected]:<YOUR_ORG>/<NEW_REPO_NAME>.git
git branch --set-upstream-to=upstream/main fork

Verify:

git remote -v
# origin    [email protected]:YOUR_ORG/NEW_REPO_NAME.git (fetch)
# origin    [email protected]:YOUR_ORG/NEW_REPO_NAME.git (push)
# upstream  https://github.com/<OWNER>/<REPO>.git (fetch)
# upstream  https://github.com/<OWNER>/<REPO>.git (push)

5. Push branches to your private repo

git push -u origin main
git push -u origin fork

6. Get to work

git switch main

👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻👨‍💻


How to work privately and use the fork

Confirmed. You can treat fork purely as your “upstream sync” branch and do all your actual work on main. Here’s the streamlined flow:

  1. Clone your private fork

    git clone [email protected]:YOUR_ORG/NEW_REPO_NAME.git
    cd NEW_REPO_NAME
  2. Ensure your remotes are set

    git remote add upstream https://github.com/ORIGINAL_OWNER/REPO.git
    # (only if you haven’t already)
  3. Update the fork branch from upstream

    git checkout fork
    # make sure fork tracks upstream/main:
    git branch --set-upstream-to=upstream/main fork
    
    git pull              # fast-forwards fork ← upstream/main
  4. Merge upstream changes into your main

    git checkout main
    git merge fork        # brings in all upstream updates
    git push origin main  # pushes your updated main to your org
  • You never commit on fork—it’s exclusively for pulling in the third-party repo’s updates.
  • All your feature work, bug-fixes, PRs, etc. happen on main (or feature branches off of main).

Shortcut: Merging upstream directly into main

If you’d rather skip the extra branch, just do:

git fetch upstream
git checkout main
git merge upstream/main
git push origin main

Either pattern keeps your main clean and your “sync” branch dedicated solely to upstream updates.

@TopherTimeMachine
Copy link

TopherTimeMachine commented Apr 25, 2025

did a git remove -v and it looked correct.

then did push -u origin master and got the following error.

[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

@devinschumacher
Copy link
Author

did a git remove -v and it looked correct.

then did push -u origin master and got the following error.

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.

i can help you but i need more info that that. can you just give me all the terminal commands/output you went through?

I've never seen that error before, but at first glance it looks like a permissions thing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment