Let’s assume you found some very interesting public repository on a GitHub that has nice features fitting perfectly into your ideas for the new software as a service project (SaaS). Let’s also assume that you want to make some additional features that you want to keep private, so you can differentiate your SaaS from the others on the market, but you want to keep possibility to sync with original public repository, so you can have the latest development merged into your code and you can contribute some bug fixes and/or features back to public repository.
Assumptions stated above describe viable business model involving open source software as a basis, but I am not going into direction of discussing business case in this post, I want to describe how to do this technically if you are developer using GitHub as a code repository hosting service.
Here is the step by step workflow described:
Create a new repo (let’s call it
private-repo) via the Github UI. Then duplicate public repo into your private-repo:
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 hotness 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
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_yourname https://github.com/yourname/private-repo.git git checkout -b pull_request_yourname git pull private_repo_yourname master git push origin pull_request_yourname
Now simply create a pull request via the Github UI for public-repo, as described here. Once project owners reviewed your pull request, they can merge it. Of course the whole process can be repeated (just leave out the steps where you add remotes).
NOTE: This post is based on Stackowerflow answer that could be seen here.