Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the last movie we got the basics of working with branches, and by now you should be able to create a new branch off of your master branch and use it to try out new ideas or implement new features. What about when you done with it? What about when your idea turns out to be successful or the future is finished, and you now want to bring those changes back into the master branch so that they're part of the main project? Well, in order to do that we need to merge them back in, and that's what we're going to learn how to do in this movie, how to bring those changes back in by merging one branch into another.
So at the moment, I'm on my seo_title branch, and we know that because in the last chapter I installed this command prompt that will show me what branch I'm on. So I'm on seo_title, let's remind ourselves what the other branches are, we have the master branch and the shorten_title branch. What I want to do is I want to merge the changes that we made from SEO title into the master branch. Now if you don't member with those changes were, we know how to do that, diff master..seo_title, and there's the changes. We just added this bit of text here at the end.
So what we are going to do is bring that change back into master so that it exists there as well. The first step is that we want to make sure that we checkout the branch that things are being merged into, the receiver. So let's do that. Let's do git checkout master. So I am in the master branch now. So the master is going to receive the changes that are in seo_title. So from the master branch I now tell it, git merge seo _title. It is that easy, just git merge seo_title. And it says, updating fast-forward, tells me summary of the changes that were made, and that's it.
Let's take a look now, let's say git log, this is the master branch log, and look here, the top commit here is modified title of index.html, and sure enough, if we now go here, and we open the index.html, we will see that our changes are in fact there. So it took the commit that was an seo title, but it did not have that snapshot of changes, and it brought that change into the master branch. So in the simplest of cases that's all there is to merging. You check out the receiving branch, then you say git merge and then the target branch or the sending branch where you're going to be getting those changes from, and that's it.
So one last step that I want us to do is let's just clear our screen, and let's do our git diff again, this time between master and seo_ title, and it comes back and tells us that there is no difference between them. If we were to use git branch --merged, which we also learned when you are comparing different branches, it'll tell us that seo_ title is fully incorporated into master. If we wanted to, now we can completely delete seo_title. We can do with the lowercase d option, and it would be deleted.
Now there is a one good tip, merges can be complicated, merges can get hairy, and we're going to talk about what to do in those cases in the upcoming movies. Because of that, you always want to run git merge with a clean working directory. You don't have any uncommitted changes, you want to go ahead and get all of those out of there. You can stash them, which we will learn how to do later, you can go and turn them into commits, but have a clean working directory, and that will give you a good clean workspace where you can sort out problems with your merges.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 92372 Viewers
82 Video lessons · 104117 Viewers
71 Video lessons · 75512 Viewers
56 Video lessons · 106903 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.