Merging Branches4:34 with Jay McGavren
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
We've discovered a problem with our code. If we run our main program, we get an error:
It points to an error in our
decoder.rbfile. Let's go fix that.
# If letter was found...
if letter != nil
# Add it onto the string.
text += letter
- 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
- One last thing. Now that we've merged the changes, we don't need the
fix-nilsbranch 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.
You need to sign up for Treehouse in order to download course files.Sign up