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 clone https://github.com/<ORIGINAL_OWNER>/<REPO_NAME>.git
Rename repo to whatever you want:
mv <REPO_NAME> <NEW_NAME>
git checkout -b fork
- Github.com → New → Repository (Do not initialize with a README, license, or .gitignore. + leave Initialize this repository unchecked)
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)
git push -u origin main
git push -u origin fork
git switch main
👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻👨💻
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
fork
branch 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
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 ofmain
).
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.
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.