| 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. |
|
- Clone the original repository locally
- Create an empty private repo in your org
- Create a local “fork” branch
- Re-assign remotes
- Push branches to your private repo
- (optional) check the it worked
- Get to work
git clone https://github.com/<ORIGINAL_OWNER>/<REPO_NAME>.git# Rename repo to whatever you want:
mv <REPO_NAME> <NEW_NAME>
# go into folder
cd <REPO_NAME> <NEW_NAME>gh api \
--method POST \
/orgs/<YOUR_ORG>/repos \
-f name='<NEW_REPO_NAME>' \
-f private=true \
-f auto_init=falsegit checkout -b forkRename 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 forkVerify:
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)git push -u origin main
git push -u origin forkgit remote show origin
git remote show upstreamgit switch mainYou can REMOVE the ability to push your now private (and probably NSWF filled) repo by running
git remote set-url --push upstream no_pushThen run git remove -v again, and you should the push remove
When you push to your origin (your fork), GitHub sees:
- Your fork has new commits
- Your fork was originally based on the place you forked from
- GitHub suggests a PR back to upstream (since it knows the relationship)
✅ To be even safer, remove Github from offering PRs back to upstream:
👉 Detach the fork on GitHub:
- Go to your fork: https://github.com/your-org/your-repo
- Click Settings
- Scroll to “Danger Zone”
- Click “Detach fork” → Confirm
This will:
- Break GitHub’s fork link
- Make GitHub stop suggesting PRs back to the original place you forked from
- Keep your repo and remotes intact — you can still git fetch upstream from CLI
Confirmed. You can treat fork purely as your “upstream sync” branch and do all your actual work on main. Here’s the streamlined flow:
-
Clone your private fork
git clone [email protected]:YOUR_ORG/NEW_REPO_NAME.git cd NEW_REPO_NAME
-
Ensure your remotes are set
git remote add upstream https://github.com/ORIGINAL_OWNER/REPO.git # (only if you haven’t already) -
Update the
forkbranch from upstreamgit checkout fork # make sure fork tracks upstream/main: git branch --set-upstream-to=upstream/main fork git pull # fast-forwards fork ← upstream/main
-
Merge upstream changes into your
maingit 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 ofmain).
If you’d rather skip the extra branch, just do:
git fetch upstream
git checkout main
git merge upstream/main
git push origin mainEither pattern keeps your main clean and your “sync” branch dedicated solely to upstream updates.

did a
git remove -vand it looked correct.then did
push -u origin masterand got the following error.[email protected]: Permission denied (publickey).fatal: Could not read from remote repository.