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!
We've merged the code that fixes the `nil` error into our `master` branch. But right now it's not available on any other topic branch. We can fix that by merging from the `master` branch into our topic branches.
We've merged the code that fixes the nil error into our master branch. But right now it's not available on any other topic branch. We can fix that by merging from the master branch into our topic branches.
- Let's try checking out our
testingbranch:git checkout testing - If we try running our unit tests, we'll see the same problem that we had with our main program:
ruby test_decoder.rb- It shows errors whenever it fails to convert a number to a letter.
- We fixed this issue, but only on the master branch.
- We need to merge commits from the
masterbranch into thetestingbranch so that the bug fix is present here as well:git merge master- This time things go a little differently. Git needs to make a new commit for this merge.
- So it brings up an editor so we can edit the commit message.
- In the previous video, we based the
fix-nilsbranch off of themasterbranch. - And then we didn't make any commits to the
masterbranch before mergingfix-nilsinto it. - So Git was able to do a "fast-forward" merge previously.
- But we have made commits to the
testingbranch since we created it. So Git can't do a fast-forward this time. - Instead, it needs to make a merge commit. This is a special type of commit that merges code from two branches together.
- That's why it displays an editor for the commit message.
- In most cases you should just keep the default message and just quit out of the editor.
- When the editor closes, Git completes the commit.
- If you run
git lognow, you'll see our "Fix error with missing letters" commit is now here on thetestingbranch.- You'll also see the merge commit at the top.
- This includes a special
Mergeline that shows partial SHA checksums for the commit's two parents. - Most commits have only one parent commit, but merge commits have two parents - the latest commits from the two branches being merged.
- The two parents in this case are the "Add test with more letters" commit from the
testingbranch, and the "Fix error with missing letters" commit from themasterbranch. - Both parent commits appear here in the history before the merge commit.
commit a305f48c593944b56df3b651d1faa52e7d87c0a6 (HEAD -> testing)
Merge: 01c21ce 0302dd0
Author: Jay McGavren <me@example.com>
Date: Sat Oct 6 13:38:09 2018 -0700
Merge branch 'master' into testing
commit 0302dd022d681ddd3e521cfc12b97fb9521e6670 (master)
Author: Jay McGavren <me@example.com>
Date: Sat Oct 6 13:20:50 2018 -0700
Fix error with missing letters
commit 01c21ced52c664acf1362fa003ffc47bcde838ce
Author: Jay McGavren <me@example.com>
Date: Wed Sep 26 20:00:18 2018 -0700
Add test with more letters
...
- We've brought our latest commits from the
masterbranch into thetestingbranch, but that doesn't bring the tests into themasterbranch. To do that, we'll need to do a merge in the other direction, fromtestingtomaster. - Since we just merged the
masterbranch into ourtestingbranch, we should be able to cleanly merge thetestingbranch into themasterbranch as well.- Let's check out the
masterbranch:git checkout master - And let's merge the
testingbranch intomaster:git merge testing - Notice that it does a fast-forward merge. This is because the latest commit from the
masterbranch is already present on thetestingbranch, thanks to the earlier merge. So Git is able to simply move themasterbranch pointer to the latest commit on thetestingbranch. - Since we already did a merge from
mastertotesting, we don't have to worry about any ugly merge conflicts when merging fromtestingtomaster.
- Let's check out the
- We no longer need the
testingbranch, so let's not forget to delete it:git branch -d testing
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