Difference between revisions of "DPS909 & OSD600 Winter 2017 - Lab 4"

From CDOT Wiki
Jump to: navigation, search
(Created page with "=Git Branches= In this lab you will review working with branches, and learn how to use the special <code>gh-pages</code> branch on Github to host static web content. ==1. Re...")
 
(3. Merging)
Line 53: Line 53:
 
==3. Merging==
 
==3. Merging==
  
 +
Next, let's experiment with merging.  We'll start by creating a third branch:
  
 +
<code>git checkout -b fav-food master</code>
  
 +
This will create a <code>fav-food</code> branch which is pointing to the same commit as <code>master</code>.  Confirm that you now have 3 branches (<code>master, name, fav-food</code>) using <code>git branch</code>.
 +
 +
On the <code>fav-food</code> branch, add a new file <code>food.txt</code> with a list of your favourite foods.  When you're done, <code>add</code> and <code>commit</code> this file to the <code>fav-food</code> branch.
 +
 +
Let's now try combining our <code>name</code> and <code>fav-food</code> branches.  If you're ever unsure about a merge, you can always try doing it on a new branch and see how it goes.  Let's try doing our merge on a branch called <code>name-and-food</code>:
 +
 +
# Create a fourth branch that points to the same commit as <code>name</code>: <code>git checkout -b name-and-food name</code>
 +
# Merge the <code>fav-food</code> branch into <code>name-and-food</code>.  When you merge, you always switch to (i.e., <code>checkout</code>) the branch into which you want to merge first, then <code>merge</code> the other branch in: <code>git merge fav-food</code>
  
  

Revision as of 11:48, 2 February 2017

Git Branches

In this lab you will review working with branches, and learn how to use the special gh-pages branch on Github to host static web content.

1. Review: creating branches

Every git repo begins with a single branch named master. When you commit, the master branch is automatically updated to point to the most recent commit.

Recall from class that we can create a new branch by doing the following:

git checkout -b new-branch

The -b flag indicates that you want to first create the branch if it does not already exist, then switch to it and check it out to your working directory. You could also have written it like this:

git checkout -b new-branch master

In this case, we are explicitly specifying that we want new-branch to be created and point to the same commit to which master is pointing. Because we're already on the master branch, we don't have to do this--git will assume you want to use the current commit. We could also have written it like this:

git checkout -b new-branch HEAD

Here we explicitly specify that we want to use the latest commit on the current branch, also known as HEAD.

If we wanted to have new-branch get created pointing to something other than the latest commit, we can specify that commit instead. For example, if we want it to point back to two commits from the current one (i.e., go back in time), we'd do this:

git checkout -b new-branch HEAD~2

As you switch between branches, if you ever get confused about which branch you're on, use git status or git branch, both of which will indicate the current branch.

2. Resetting a Branch

Sometimes it's necessary to switch the commit to which a branch is pointing. For example, if you accidentally commit things on master vs. a new branch, and need to move master back to a commit in the same history as a remote repository (i.e., if you want to git pull upstream master to get new updates).

Let's walk through an example:

  1. On Github, fork the Spoon-Knife repository at https://github.com/octocat/Spoon-Knife
  2. Clone this repository to your local computer
  3. Confirm that you are on the master branch (i.e., use git branch)
  4. Create a new file called name.txt with your first name in it
  5. Use git to add and commit the new name.txt file.
  6. Confirm that you have 1 new commit on the master branch (i.e., use git log)

At this point we have a new commit on the master branch, but decide that we should have done this work on a new branch. Let's fix things so master is back where it should be, and we instead have a new branch:

  1. Create a new branch called name by doing git checkout -b name
  2. Confirm that you are now on the name branch
  3. Confirm that name and master both point to the same commit (i.e., use git show name and git show master)

We can now move our master branch back one commit, and leave our name branch where it is. We'll do that using the -B flag (note the capital), which will create or reset a branch:

  1. git checkout -B master HEAD~1
  2. Confirm that name and master both point to different commits (i.e., use git show name and git show master)

3. Merging

Next, let's experiment with merging. We'll start by creating a third branch:

git checkout -b fav-food master

This will create a fav-food branch which is pointing to the same commit as master. Confirm that you now have 3 branches (master, name, fav-food) using git branch.

On the fav-food branch, add a new file food.txt with a list of your favourite foods. When you're done, add and commit this file to the fav-food branch.

Let's now try combining our name and fav-food branches. If you're ever unsure about a merge, you can always try doing it on a new branch and see how it goes. Let's try doing our merge on a branch called name-and-food:

  1. Create a fourth branch that points to the same commit as name: git checkout -b name-and-food name
  2. Merge the fav-food branch into name-and-food. When you merge, you always switch to (i.e., checkout) the branch into which you want to merge first, then merge the other branch in: git merge fav-food





After you've picked your bug, add your name and the issue number to the table below

# Name Spoon-Knife Repo (URL) Hosted gh-pages Site (URL)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

Submission

You will have completed your lab when you have done the following:

  • Setup Bramble and Thimble on your local computer, and taken a screenshot of it running in your browser
  • Picked a bug to fix in Thimble
  • Written a blog post discussing what it was like setting up Thimble, what you learned, and which bug you chose. What is the bug about?
  • Added a row to the table above with your name, issue URL, and blog post URL.