Difference between revisions of "DPS909 & OSD600 Winter 2017 - Lab 4"
(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...") |
(No difference)
|
Revision as of 11:38, 2 February 2017
Contents
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:
- On Github, fork the Spoon-Knife repository at https://github.com/octocat/Spoon-Knife
- Clone this repository to your local computer
- Confirm that you are on the
master
branch (i.e., usegit branch
) - Create a new file called
name.txt
with your first name in it - Use git to
add
andcommit
the newname.txt
file. - Confirm that you have 1 new commit on the
master
branch (i.e., usegit 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:
- Create a new branch called
name
by doinggit checkout -b name
- Confirm that you are now on the
name
branch - Confirm that
name
andmaster
both point to the same commit (i.e., usegit show name
andgit 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:
-
git checkout -B master HEAD~1
- Confirm that
name
andmaster
both point to different commits (i.e., usegit show name
andgit 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.