Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed Git Branches and Merging!
You have completed Git Branches and Merging!
The `testing` branch we created in the previous video is an example of a __topic branch__. A "topic" is defined as "a matter dealt with in a book or article". Examples of topics in your _code_ might include changing the colors on a website, or adding a new feature to a program. When you're working on new features or bug fixes, it's best to do it on a branch, a topic branch, that deals exclusively with commits for that feature.
The testing branch we created in the previous video is an example of a topic branch. A "topic" is defined as "a matter dealt with in a book or article". Examples of topics in your code might include changing the colors on a website, or adding a new feature to a program. When you're working on new features or bug fixes, it's best to do it on a branch, a topic branch, that deals exclusively with commits for that feature.
$ git branch color-theme
$ git branch reply-all
- Our decoder library doesn't actually contain any translations from numbers to letters yet. I'm going to add some now, for the letters A through E.
1 => 'A',
2 => 'B',
3 => 'C',
4 => 'D',
5 => 'E',
- But this is a new topic within our code, so we don't just want to commit it to an existing branch. We want to create a new branch before we make any commits.
- The new branch will be based on whatever branch is checked out when we create it.
- Because we're going to be merging this code into the
masterbranch later, we want our new branch to be based on themasterbranch. - So we need to be sure the
masterbranch is checked out:git checkout master - We'll show you what would happen if a different topic branch were checked out in the next video.
- Because we're going to be merging this code into the
- Now let's create a branch to hold our new letter translations.
- This time, I'm going to use a shortcut that creates and checks out the new branch all in one step.
- We don't run
git branchat all. - Instead, we add the
-bcommand-line option to thegit checkoutcommand:git checkout -b add-letters - This will cause the branch we specify to be created before checking it out.
- We don't run
- If you run
git branch, then as before you'll see our newadd-lettersbranch. It already has a star in front of it, showing that it's checked out. - Now let's make a commit to our new branch.
- I'll stage the file that includes our changes:
git add decoder.rb - And commit it:
git commit -m "Add A-E" - If I run
git lognow, we'll see the commit for thisadd-lettersbranch:git log - As before, the new commit is added at the top, and the
add-lettersbranch is moved to point to it. - The
masterbranch stays pointing at the same commit it was before.
- I'll stage the file that includes our changes:
commit af94e112210c0c7b15f8ed94ca51d090dfe56587 (HEAD -> add-letters)
Author: Jay McGavren <me@example.com>
Date: Fri Sep 28 13:15:36 2018 -0700
Add A-E
commit 21428a2eee8e55becb6da879228446746ad6f1a8 (master)
Author: Jay McGavren <me@example.com>
Date: Tue Sep 25 08:34:12 2018 -0700
Add main program
commit e40647094c74d64fb7c4dee7351139c3ba644d9c
Author: Jay McGavren <me@example.com>
Date: Tue Sep 25 08:22:59 2018 -0700
Add decode function
- The repository looks like this.
- We've added a new commit, and the new
add-lettersbranch has been moved to point to it. - This
add-lettersbranch is based off themasterbranch, but its commit history is totally separate from thetestingbranch we created earlier.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up