I just did something similar to this.
The solution what worked for me was to create a new private Repo as a bare clone of your main repo, and push the all the new changes to this private repo, and once the changes are ready to be made public, push the changes to the public repo.
- First, duplicate the repo as others said (details here):
Create a new repo (let's call it private-repo) via the Github UI. Then:
git clone --bare https://github.com/exampleuser/public-repo.git
cd public-repo.git
git push --mirror https://github.com/yourname/private-repo.git
cd ..
rm -rf public-repo.git
Clone the private repo so you can work on it:
git clone https://github.com/yourname/private-repo.git
cd private-repo
make some changes
git commit
git push origin master
3.To pull new Changes from the public repo:
cd private-repo
git remote add public https://github.com/exampleuser/public-repo.git
git pull public master # Creates a merge commit
git push origin master
Awesome, your private repo now has the latest code from the public repo plus your changes.
- Finally, to create a pull request private repo -> public repo:
The only way to create a pull request is to have push access to the public repo. This is because you need to push to a branch there (here's why).
git clone https://github.com/exampleuser/public-repo.git
cd public-repo
git remote add private_repo https://github.com/yourname/private-repo.git
git checkout -b pull_request_branch
git pull private_repo master
git push origin pull_request_branch
Now simply create a pull request via the Github UI for public-repo, as described here.
Once project you review the pull request, you can merge it.
Of course the whole process can be repeated (just leave out the steps where you add remotes). After the first time you just have to pull from the required remote (Public or Private) and push to the (private). Once done with the changes, push the changes to (private : to keep it up to date) and some branch on Public so a pull request to master can be created.