Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
You have two branches. Both have changes you need, but when you check one out the changes in the other are no longer available. How do you get access to both at once? You merge the branches!
Merging takes the contents of your files from one branch, and merges them with the contents of your files in another branch.
You can merge any branch into any other branch, although it's most commonly used to bring the contents of a topic branch into the
master
branch.We've discovered a problem with our code. If we run our main program, we get an error:
ruby try_decoder.rb
It points to an error in our
decoder.rb
file. Let's go fix that.
# If letter was found...
if letter != nil
# Add it onto the string.
text += letter
end
- Let's check out a new topic branch to commit this to:
git checkout -b fix-nils
- And then commit the file:
git add decoder.rb
git commit -m 'Fix error with missing letters'
- Now, check out the branch you're going to merge into:
git checkout master
- Merge the other branch into the checked out branch:
git merge fix-nils
- Now our bug fix is available on the
master
branch.
Deleting branches
- One last thing. Now that we've merged the changes, we don't need the
fix-nils
branch any more.- In fact, having it around could confuse you later, if you don't remember what it's for.
- So we need to delete it:
git branch -d fix-nils
- If the branch weren't merged, we'd get a warning before deleting it, but because we've merged the branch into another branch, Git just goes ahead and deletes it for us.
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