Connected Lab 11

Working with Submodules

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

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 submodule to super_calc.
  2. Add the sub_ui repository as a submodule to the super_calc project by running this command:
    $ git submodule add https://github.com/<your github userid>/sub_ui sub_ui
  3. This adds sub_ui as a submodule to your super_calc repository. In the process, Git clones down the repository into the subdirectory and also creates and stages a .gitmodules file to map the connection with the super_calc project. Look at the directory listing to see the new subdirectory. Then look at the status to see the staged .gitmodules file. Finally, display the contents of the .gitmodules file to see what’s in there. Run the following commands from the super_calc subdirectory:
    $ ls
    $ git status
    $ git show :.gitmodules
  4. Now you need to commit and push the staged submodule mapping and data to your local and remote repositories. Run the following commands:
    $ git commit -m "Add submodule sub_ui"
    $ git push
  5. Now you can clone a new copy of this project with the submodule. Change to a higher-level directory and clone a copy of the project down as super_calc2.
    $ cd ..
    $ git clone https://github.com/<your github userid>/super_calc super_calc2
  6. Change into the super_calc2 directory and look at what’s in the sub_ui subdirectory. Run the submodule status command to see what the status of the submodule is.
    $ cd super_calc2
    $ ls sub_ui
    $ git submodule status
  7. Notice the hyphen (-) in front of the SHA1 value. This indicates that the submodule has not been initialized yet relative to the super project. You could have done this at clone time using the --recursive option. However, because you didn’t, you need to use the update --init subcommand for the submodule operation, as follows:
    $ git submodule update --init
  8. Git clones the sub_ui code into the submodule. Look at the sub_ui subdirectory to see the contents, and then run the submodule status command again.
    $ ls sub_ui
    $ git submodule status

    This time, you see a space at the beginning (instead of the minus sign) to indicate the submodule has been initialized.

  9. Now, you need to make a simple update to the code in the submodule. Change into the sub_ui subdirectory (cd sub_ui) and edit the calc.html file there as follows: change the line
    <title>Advanced Calculator</title>

    in the file to

    <title> your_name_here Advanced Calculator</title>

    substituting your actual name for “your_name_here”. Save your changes.

  10. Commit your changes into the submodule.
    $ git commit -am "Update title"
  11. Do a quick log command and note the SHA1 value associated with the commit you just made.
    $ git log --oneline
  12. Change back to the super_calc2 project (up one level) and run a submodule status command.
    $ cd ..
    $ git submodule status
  13. Note that the submodule SHA1 reference now points to your latest commit in the submodule, but there is a plus sign (+) at the front of the reference. This indicates that there are changes in the submodule that have not yet been committed back into the super project. Run a git status command to get another view of what’s changed for the super project.
    $ git status
  14. The status command gives you much more information about what’s changed. It tells you that the sub_ui module has been changed and is not updated or staged for commit. To complete the update, you need to stage and commit the sub_ui data. You can then push it out to your GitHub remote repository. To complete the process, execute the commands below.
    $ git commit -am "Update for submodule sub_ui"
    $ git push
  15. Now that you’ve updated the submodule and the supermodule, everything is in sync. Run a git status and a git submodule status command to verify this.
    $ git status
    $ git submodule status
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset