Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
In the last movie, we created a new branch called new feature, but we haven't switched to it yet. The currently checked out branch is still master, and we know that because we can say git branch, and it gives us a list of the branches and puts some asterisks next to master to let us know that that's still the currently checked out branch, that's what's in our working directory. We saw that we can also take a look at the .git file to see where the HEAD points, and we can see that it also points to the master branch as well right now. So let's see how we check out the new branch.
We do that by checking out the branch, so git checkout is the command that we're going to want, git checkout followed by the name of the branch, git checkout new_feature. And we hit Return, it comes up and tells us that it switched to the branch new feature. Git branch now confirms that we've made the switch, and if we take a look at cat .git/HEAD, we'll see that it also now points to the new_feature branch instead. Now at this point, they both point to the same commit. We haven't made any new changes to master, we haven't made any new changes to new feature, so the tips of those still are absolutely identical.
If we switch between them, no files change in our working directory. Let's add a commit to new feature. Let's just open up index.html, and where it says Welcome to Explore California in the title, let's just add Affordable Outdoor Tours, Save that, git status. We can see that it's here and our changes are not staged for commit. I'm going to commit it, and I am going to use the -a option, which will take all of the changes that are in my not staged for commit, and commit them all at once, and automatically add them as well as commit them, and let's call this modified title of index.html.
So now we have that commit made. Let's take a look, git log --oneline. We can see it, Modified title of index.html, here is the commit number, dc9c83c, so now let's do git checkout of master. Switch back to the branch master, we can confirm that with the git branch. Now let's do git log --oneline, oop, typo there. Now you can see that it's not there anymore. 380f is the last one, which was the second to last one here.
So we have a new commit that's on one and not the other. And now that we're on master, let's go back and take a look at index.html. Welcome to Explore California, let's close that file up. Let's switch our branch again, git checkout new_ feature, switch back to the branch new_feature. Let's open up index.html again. Notice that it changes back again, this is the fast context switching that I was talking about. It's that easy to just swap out all the files and folders in your working directory just by typing checkout a different branch.
In the next movie, we're going to see how we can both create a branch and check it out at the same time.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 99910 Viewers
56 Video lessons · 113013 Viewers
71 Video lessons · 81845 Viewers
131 Video lessons · 39281 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.