Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
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
testing
branch: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
master
branch into thetesting
branch 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-nils
branch off of themaster
branch. - And then we didn't make any commits to the
master
branch before mergingfix-nils
into it. - So Git was able to do a "fast-forward" merge previously.
- But we have made commits to the
testing
branch 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 log
now, you'll see our "Fix error with missing letters" commit is now here on thetesting
branch.- You'll also see the merge commit at the top.
- This includes a special
Merge
line 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
testing
branch, and the "Fix error with missing letters" commit from themaster
branch. - 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
master
branch into thetesting
branch, but that doesn't bring the tests into themaster
branch. To do that, we'll need to do a merge in the other direction, fromtesting
tomaster
. - Since we just merged the
master
branch into ourtesting
branch, we should be able to cleanly merge thetesting
branch into themaster
branch as well.- Let's check out the
master
branch:git checkout master
- And let's merge the
testing
branch intomaster
:git merge testing
- Notice that it does a fast-forward merge. This is because the latest commit from the
master
branch is already present on thetesting
branch, thanks to the earlier merge. So Git is able to simply move themaster
branch pointer to the latest commit on thetesting
branch. - Since we already did a merge from
master
totesting
, we don't have to worry about any ugly merge conflicts when merging fromtesting
tomaster
.
- Let's check out the
- We no longer need the
testing
branch, so let's not forget to delete it:git branch -d testing
We've merged the code that fixes the mail
error into our master branch, but
0:01
right now it's not available
on any other type of branch.
0:05
We can fix that by merging from the master
branch into our topic branches.
0:08
Let's try checking out our testing branch.
0:13
Git checkout testing.
0:16
If we try running our unit test,
0:20
we'll see the same problem that
we had with our main program.
0:22
It shows errors whenever it fails
to convert a number to a letter.
0:26
We fix this issue, but
only on the master branch.
0:30
If we run git log here on the testing
branch, we won't see that commit.
0:34
git log.
0:38
And there's no mention of the commit to
fix the issue with the missing letters.
0:40
We need to merge commits from the master
branch into the testing branch so
0:45
that the bug fix is present here as well.
0:48
We do that of course with
the git merge command, and
0:51
we specify the branch that we want
to merge into the current branch.
0:54
So we're going to merge the master
branch into the currently checked out
0:57
testing branch.
1:01
This time things go a little differently.
1:03
Git needs to make a new commit for
this merge, so it brings up an editor so
1:05
we can edit the commit message.
1:09
In the previous video we based the fixed
nils branch off of the master branch and
1:12
we didn't make any commits to the master
branch before merging fix nils into it.
1:16
So git was able to do a fast
forward merge previously.
1:21
But we have made commits to the testing
branch since we created it, so
1:25
git can't do a fast-forward this time.
1:28
Instead it needs to make a merge commit.
1:31
This is a special type of commit that
merges code from two branches together.
1:33
That's why it displays an editor for
the commit message.
1:38
In most cases, you should just
keep the default message, so
1:42
I'll just quit out of the editor.
1:45
When the editor closes,
git completes the commit.
1:47
And if we run git log now, you'll see our
fix arrow with missing letters commit
1:51
is now here on the testing branch.
1:56
You'll also see the merge
commit up here at the top.
1:59
This includes a special merge line
that shows partial SHA check sums for
2:03
the commit's two parents.
2:07
Most commits have only one parent.
2:09
But merge commits have two parents,
2:12
the latest commits from
the two branches being merged.
2:14
The two parents, in this case,
2:17
are the add test with more letters commit,
From the testing branch,
2:19
and the fix error with missing
letters commit from the master branch.
2:24
Both parent commits appear here in
the history before the merge commit.
2:28
We've borrowed our latest commits from the
master branch into the testing branch, but
2:33
that doesn't bring the test
into the master branch.
2:36
To do that,
2:39
we'll need to do a merge in the other
direction, from testing to master.
2:40
Since we just merged the master branch
into our testing branch, we should be able
2:45
to cleanly merge the testing branch
into the master branch as well.
2:48
Let's checkout the master branch.
2:52
Git checkout master.
2:54
And let's merge the testing
branch into master.
2:58
Git merge testing.
3:01
Notice that it does a fast-forward merge.
3:03
This is because the latest commits
from the master branch are already
3:06
present on the testing branch,
thanks to the earlier merge.
3:09
So git is able to simply move the master
branch pointer to the latest commit
3:12
on the testing branch.
3:17
Since we already did a merge from master
to testing, we don't have to worry about
3:18
any ugly merge conflicts when
merging from testing to master.
3:22
Now that our testing branch
has been merged into master,
3:27
we can run our unit tests from
the master branch as well.
3:29
Those tests still aren't passing,
but they're here and
3:36
ready to run to help us clean up
our code on our other branches.
3:38
We no longer need the testing branch, so
3:43
let's not forget to delete it,
git branch -d testing.
3:44
So far we've had a pretty easy time
merging branches but what happens when
3:49
two different branches both try to
change the same section of code?
3:54
We'll learn how to resolve merge
conflicts in the next video.
3:58
You need to sign up for Treehouse in order to download course files.
Sign up