O'Reilly logo

Professional Git by Brent Laster

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Connected Lab 12

Working with Subtrees

In this lab, you’ll get some experience working with subtrees.

PREREQUISITES

This lab requires that you have Internet access and have completed at least the first two steps in Connected Lab 10, where you forked the various split projects of the original calc2 project into your area in GitHub and cloned the super_calc project down to your local system.

STEPS

  1. Start out in the super_calc directory for the super_calc repository that you cloned from your GitHub fork in Connected Lab 10. You’re going to add another repository as a subtree to super_calc.
  2. To add the repository, use the following command:
    $ git subtree add -P sub_docs --squash https://github.com/<your github user id>/sub_docs master

    Even though you don’t have much history in this repository, you used the --squash command to compress it. Note that the -P stands for prefix, which is the name your subdirectory gets.

  3. Look at the directory structure; note that the sub_docs subdirectory is there under your super_calc project. Also, if you do a git log, you can see where the subproject was added and the history squashed.
    $ ls sub_docs
    $ git log --oneline

    Note that there is only one set of history here because there is only one project effectively—even though we have added a repository as a subproject.

  4. Now, you will see how to update a subproject that is included as a subtree when the remote repository is updated. First, clone the sub_docs project down into a different area.
    $ cd .. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required