--- title: "How to Create a Private “Fork” of a Public GitHub Repo" description: "Step-by-step guide to clone a public repo into a private repository in your organization while still pulling in upstream changes." tags: - git - github - private-fork - cli --- # How to Create a Private “Fork” of a Public GitHub Repo | Step-by-step Guide 1. [Clone the original repository locally](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#1-clone-the-original-repository-locally) 2. [Create an empty private repo in your org](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#2-create-an-empty-private-repo-in-your-org) 3. [Create a local “fork” branch](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#3-create-a-local-fork-branch) 4. [Re-assign remotes](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#4-re-assign-remotes) 5. [Push branches to your private repo](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#5-push-branches-to-your-private-repo) 6. [(optional) check the it worked](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#6-optional-check-the-it-worked) 7. [Get to work](https://gist.github.com/devinschumacher/c0d45bc626999f19df5429c5cd549a8c/edit#7-get-to-work) ## Click here to watch the video 👇 --- ## 1. Clone the original repository locally ```bash git clone https://github.com//.git ``` ```bash # Rename repo to whatever you want: mv # go into folder cd ``` ## 2. Create an empty private repo in your org ```bash gh api \ --method POST \ /orgs//repos \ -f name='' \ -f private=true \ -f auto_init=false ``` ## 3. Create a local “fork” branch ```bash git checkout -b fork ``` ## 4. Re-assign remotes Rename the existing `origin` (public repo) to `upstream` and add your private repo as `origin`: ```bash git remote rename origin upstream git remote add origin git@github.com:/.git git branch --set-upstream-to=upstream/main fork ``` Verify: ```bash git remote -v # origin git@github.com:YOUR_ORG/NEW_REPO_NAME.git (fetch) # origin git@github.com:YOUR_ORG/NEW_REPO_NAME.git (push) # upstream https://github.com//.git (fetch) # upstream https://github.com//.git (push) ``` ## 5. Push branches to your private repo ```bash git push -u origin main git push -u origin fork ``` ## 6. (optional) check the it worked: ```bash git remote show origin git remote show upstream ``` ## 7. Get to work ```bash git switch main ``` ## (optional) BUT VERY SAFE ### 1. Remove `push` ability to the upstream You can REMOVE the ability to push your now private (and probably NSWF filled) repo by running ```bash git remote set-url --push upstream no_push ``` Then run `git remove -v` again, and you should the push remove ⚠️ However: GitHub pull requests are not tied to git push remotes. 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: 1. Go to your fork: https://github.com/your-org/your-repo 2. Click Settings 3. Scroll to “Danger Zone” 4. 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 --- # Example ## 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** ```bash git clone git@github.com:YOUR_ORG/NEW_REPO_NAME.git cd NEW_REPO_NAME ``` 2. **Ensure your remotes are set** ```bash git remote add upstream https://github.com/ORIGINAL_OWNER/REPO.git # (only if you haven’t already) ``` 3. **Update the `fork` branch from upstream** ```bash 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`** ```bash 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: ```bash 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.