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.
I followed the steps from : Answer to this question by: Martin Konicek
Duplicate the repo (details here):
Create a new repo (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
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
The private repo now has the latest code from the public repo plus your changes.
- Create a pull request private repo -> public repo:
Ceating a pull request requires push access to the public repo 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.
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.