On a project I’m working on, I was interested in cloning a large git repository on GitHub (Azure Quickstart ARM Templates) and splitting out a few pieces for further development while still merging changes from the original repository.
Essentially, I wanted to split out a folder of the parent repo.
Now, I’m not a git expert (yet) and this still needs some further testing, but I think I figured it out and this post serves as my way of recording this for future enhancement. If you’ve got suggestions/questions, please post them in the comments or e-mail me as I’d love to grow this.
Original repo: https://github.com/Azure/azure-quickstart-templates.git
Directory of interest: https://github.com/Azure/azure-quickstart-templates/tree/master/chef-json-parameters-ubuntu-vm
Destination working repo: https://mygitlab.server/pg_chef-json-parameters-ubuntu-vm
Clone the original repo:
git clone https://github.com/Azure/azure-quickstart-templates.git
Add the new repo as a remote
git remote add pg_chef-json-parameters-ubuntu-vm https://mygitlab.server/azure-infra/pg_chef-json-parameters-ubuntu-vm.git
Split the desired folder into a new branch (named here specific to my project):
git subtree split --prefix=chef-json-parameters-ubuntu-vm -b pg_chef-json-parameters-ubuntu-vm
Note: this takes a while on this particular repo…
Push the branch to the new repo:
git push https://mygitlab.server/azure-infra/pg_chef-json-parameters-ubuntu-vm.git pg_chef-json-parameters-ubuntu-vm:master
Clone the new repo locally:
git clone https://mygitlab.server/azure-infra/pg_chef-json-parameters-ubuntu-vm.git
And now you’re ready to go!!
This was adapted from John Teague’s post on Se Habla Code Los Techies. His example is a bit more complex and way cooler in that he sets up a scenario where he splits out the web UI of an application that is identical between two different supported app layers. In his example, the web UI is split out, deleted from the original repository and then added back into both of the app layer repos as a remote.
Sounds very cool and I need to try that… Thanks John!!!