Since you copied this from slingshot, the new repository will still have any remote tracking branches you setup when it was slingshot. Git filter-branch -subdirectory-filter rubber-band -allĪt this point, you’ll have a folder rubber-band, which is a repository that sort of resembles Project Slingshot, but it only has the files and commit history from the rubber-band folder. It looks like rubber-band is just another slingshot, but now, from the rubber-band repository, run git filter-branch: cd rubber-band You can use cp with -r to recursively copy the entire slingshot folder to a new folder rubber-band. The first step is to make a copy of slingshot to work on-the end-goal is for rubber-band to stand as its own repository, so leave slingshot as is. For more information on git filter-branch, see this article. The git filter-branch command will rewrite our repository’s history, making it look as if the rubber-band folder had been it’s own repository all along. You can use git filter-branch to do this, leaving you with just the commits related to rubber-band. Let’s begin by extracting the contents of the rubber-band folder out of slingshot. You can take everything from the Project Slingshot’s rubber-band folder and extract it into a new repository and even maintain the commit history. Let’s take the rubber-band you built for slingshot, split it out into a stand-alone repository, and then embed it into both projects via submodules. You’re about to start a new project-a magic roll-back can–which also needs a rubber-band. It can be a little tricky to take an existing subfolder and turn it into an external dependency. You can use git submodule update -init -recursive here as well, but if you’re cloning slingshot for the first time, you can use a modified clone command to ensure you download everything, including any submodules: git clone -recursive Switching to submodules At this point, if you were to peek inside the rock folder, you’d see … nothing.Īgain, Git expects us to explicitly ask it to download the submodule’s content. You’d start by running git clone to download the contents of the slingshot repository. Now, say you’re a new collaborator joining Project Slingshot. Git log # commits from Rock Joining a project using submodules Git log # still commits from Project Slingshot Git log # log shows commits from Project Slingshot On the command-line, Git commands issued from slingshot (or any of the other folders, rubber-band and y-shaped-stick) will operate on the “parent repository”, slingshot, but commands you issue from the rock folder will operate on just the rock repository: cd ~/projects/slingshot You can interact with all the content from rock as if it were a folder inside slingshot (because it is). That’s it! You’ve embedded the rock repository inside the slingshot repository. On GitHub, the rock folder icon will have a little indicator showing that it is a submodule:Īnd clicking on the rock folder will take you over to the rock repository. If everything looks good, you can commit this change and you’ll have a rock folder in the slingshot repository with all the content from the rock repository. Newer versions of Git will do this automatically, but older versions will require you to explicitly tell Git to download the contents of rock: git submodule update -init -recursive In the slingshot repository: git submodule add rockĪt this point, you’ll have a rock folder inside slingshot, but if you were to peek inside that folder, depending on your version of Git, you might see … nothing. You can add rock as a submodule of slingshot. You’ve got code for y-shaped stick and a rubber-band.įlickr photo shared by under a Creative Commons ( BY ) licenseĪt the same time, in another repository, you’ve got another project called Rock-it’s just a generic rock library, but you think it’d be perfect for Slingshot. Let’s say you’re working on a project called Slingshot. Submodules allow you to include or embed one or more repositories as a sub-folder inside another repository.įor many projects, submodules aren’t the best answer (more on this below), and even at their best, working with submodules can be tricky, but let’s start by looking at a straight-forward example. Git provides submodules to help with this. Eventually, any interesting software project will come to depend on another project, library, or framework.
0 Comments
Leave a Reply. |