Following the fantastic answer
There is a public repo we want to fork, but we want to make our forked repo private, and also can make a pull request to the public repo.
Basic idea: we create a public forked repo as usual, but serving as an agent.
The relationship in remote add (A <- B means cd A; git remote add B):
Forked Repo <- Private Repo <- Public Repo
But in the github UI of the Forked Repo, we can still make a pull request to the Public Repo. So the actual dependency graph is cyclic: Forked Repo -> Public Repo where -> means making pull request.
First create an emtpy private repo https://github.com/yourname/private-repo.git, then run
git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo
git push --mirror https://github.com/yourname/private-repo.git # mirror the public repo into private repo
cd ..
rm -rf public-repo # we don't use it anymoregit clone https://github.com/yourname/private-repo.git
cd private-repo
git remote add public https://github.com/exampleuser/public-repo.git # add remote of publicUse the GitHub UI to create a fork of the public repo (the small "Fork" button at the top right of the public repo page). Then:
git clone https://github.com/yourname/the-fork.git
cd the-fork
git remote add private_repo_yourname https://github.com/yourname/private-repo.git # add remote of privategit pull in our private repo directly
cd private-repo
git pull public <branch> # Creates a merge commit
git push origin <branch>Just feel free to make changes in the private repo in any branches we like.
git checkout -b <new branch> <old branch>
# git checkout -b <new branch> # is the default old branch = main
When making pull request, we can change the base branch as the parent branch (in the github website) that current branch inherits, for better visualization in comparison.
We have to use the forked repo as an agent:
cd the-fork
# if the branch does not exist:
git checkout -b <branch>
# else
git checkout <branch>
git pull private_repo_yourname <branch>
git push origin <branch>Then use github UI to make a pull request!
commit the changes