Connected Lab 10

Working with Worktrees

In this lab, you’ll get some experience with worktrees. For this and the subsequent labs, I have split the calc2 repository that you used in the last lab into three separate projects.

PREREQUISITES

This lab requires that you have Internet access and have completed Connected Lab 8: Setting up a GitHub Account and Cloning a Repository. You will be working in a new directory.

STEPS

  1. For this lab, you need access to your GitHub account that you set up in Connected Lab 8. I have split up the calc2 project you used in Connected Lab 9 into three separate projects: super_calc, a version of the calc2 project with only the master and feature branches; sub_ui, a separate repository consisting of only the content of the ui branch split out from the calc2 project; and sub_docs, a separate repository consisting of only the content of the docs branch split out from the calc2 project. Log in to your GitHub account and fork the three projects from the following listed locations. (As a reminder, the fork button is in the upper-right corner of the pages.) This will prepare your area on GitHub for doing this lab, as well as Connected Labs 11 and 12.

    https://github.com/professional-git/super_calc.git
    https://github.com/professional-git/sub_ui.git
    https://github.com/professional-git/sub_docs.git

  2. In a new directory, clone down the super_calc project that you forked in step 1, using the following command:
    $ git clone https://github.com/<your github userid>/super_calc.git
  3. Now, change into the cloned directory—super_calc.
    $ cd super_calc
  4. In this case, you want to work on both the master branch and the features branch at the same time. You can work on the master branch in this directory, but you need to create a separate working tree (worktree) for working on the features branch. You can do that with the worktree add command, passing the -b to create a new local branch off of the remote tracking branch.
    $ git worktree add -b features ../super_calc_features origin/features
  5. Change into the new subdirectory with the new worktree. Note that you are on the features branch. Edit the calc.html file and update the line in the file surrounded by <title> and </title>. The process is described below.
    $ cd ../super_calc_features

    Edit calc.html and change

    <title>Calc</title>

    to

    <title> github_user_id's Calc</title> 

    substituting in your GitHub user ID for “github_user_id”.

  6. Save your changes and commit them back into the repository.
    $ git commit –am "Updating title"
  7. Switch over to your original worktree.
    $ cd ../super_calc
  8. Look at what branches you have there.
    $ git branch
  9. Note that you have the features branch you created for the other worktree. Do a log on that branch; you can see your new commit just as if you had done it in this worktree.
    $ git log --oneline features
  10. You no longer need your separate worktree. However, before you remove it, take a look at what worktrees are currently there.
    $ git worktree list
  11. You can now remove the worktree. First, remove the actual directory; then use the prune option to get rid of the worktree reference.
    $ rm –rf ../super_calc_features
    $ git worktree prune
..................Content has been hidden....................

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