# Creating a Private Fork of a GitHub Repository
## Basic Steps
1. Create a new [private repository on Github](https://help.github.com/articles/creating-a-new-repository/)
2. Fork the repo (`BASE_REPO_URL`) to your new private repo (`PRIVATE_REPO_URL`) as follows:
```bash
BASE_REPO_URL= # remote URL of repo you are forking
PRIVATE_REPO_URL= # remote URL of your new private fork repo
# Create a bare clone of the base repo
git clone --bare $BASE_REPO_URL
# Mirror-push your bare clone to your new private repo
cd ${BASE_REPO_URL##*/}
git push --mirror $PRIVATE_REPO_URL
# Remove the temporary local repository you created in step 2
cd ..
rm -rf ${BASE_REPO_URL##*/}
```
---
## Recommended Additional Steps
`cd` to your preferred workspace, then clone your private fork
```bash
git clone $PRIVATE_REPO_URL # clone the private fork
cd ${${PRIVATE_REPO_URL##*/}%%.git} # cd into the cloned directory
# add the original repo as remote to fetch (potential) future changes.
git remote add upstream $BASE_REPO_URL
# disable push on the remote (as you are not allowed to push to it anyway).
git remote set-url --push upstream DISABLE
```
* You can list all your remotes with `git remote -v`. You should see:
```
origin (fetch)
origin (push)
upstream (fetch)
upstream DISABLE (push)
```
* When you push, do so on `origin` with `git push origin`.
* When you want to pull changes from `upstream` you can just fetch the remote and rebase on top of your work.
```bash
git fetch upstream
git rebase upstream/main
```
Additional information on creating a private fork by duplicating a repo is documented [here](https://help.github.com/articles/duplicating-a-repository/).
see also: https://ellisbrown.github.io/programming/git-private-forks/#basic-steps