Open main menu

CDOT Wiki β

DPS909 & OSD600 Winter 2017 - Lab 4

Revision as of 12:38, 2 February 2017 by David.humphrey (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

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.