In this lesson, you’ll learn how to go through git commit history to checkout old commits. You’ll also learn what the terms master, HEAD, and branch mean.
Git Checkout and Intro to Branches
00:01 You’re going to like this. Git has another cool feature. It can travel forward and backwards in time. While we can’t quite go back and see a T-Rex, you can move forwards and backwards in the timeline of your project.
This is done with a command called
checkout. In this module, you’re going to learn a couple of new and important terms named
branch, so let’s hop into the console and see if you can spot the terms.
So hop back into your Python console, grab the rest of The Zen of Python—you stopped on line 7, somewhere around here. Just grab the rest of it, copy it, hop back into your repo, open your
zen_of_python file. If you’re using VIM, hit
i for insert, hop down to the next line, and paste everything in.
02:20 Well, that just blasted you with a bunch of information, huh? That’s the kind of message that makes you sweat a little bit. Let’s small chunk this, so we can kind of digest this message. First, Git verifies that it is checking out the commit.
And from this message, we see that we can make experimental changes in this quote-unquote
'detached HEAD' state. And it tells us if we want to retain commits, we’d need to create another branch.
Now let’s go check out a diagram. Check this out. You’ve been working in what’s known as a branch the whole time, and it’s called the
master branch. When you initialize your Git repo, it creates the
master branch automatically.
So, going back to the earlier example from our console, you got a warning that you were in what’s called a
'detached HEAD' state.
HEAD is just a pointer indicating where you are within your branches and/or commits within the project.
HEAD sits at the end of whatever branch you have checked out. The first time you ran
checkout, Git moved
HEAD to point at the first commit and it was warning you that you weren’t in the most current area of development for the
04:32 So this detached state is good for traversing and viewing the timeline of a project, but we shouldn’t use it for writing new code and features, especially when working on a team. For that, we’ll start using branches, and we’ll discuss them in the next video.
Become a Member to join the conversation.