The solution comes after understanding what checkout does actually and how things work.
When you initially create a commit, git automatically creates a branch with the default known name master
.
C1
^
|
master
As you can see, C1 represents the initial commit. There's a pointer (branch), which is master
, that points to C1.
When you create another commit, the pointer moves on to the new one:
C1 <- C2
^
|
master
master now points to C2. C2 has a parent which is C1. Every commit points to the preceding commit.
There's one more pointer not shown in the figures. This is HEAD pointer. The HEAD points to the current commit you are on. Meaning, if you are C2, HEAD points to C2. This helps you to jump between commits easily.
At this point of time, if you checkout to C1, you are moving the HEAD pointer to point to C1 and leave (detach from) C2.
Therefore, in most cases, if you checkout to another commit, you generally at some later point, you checkout back again to the most recent commit.
This part of the tutorial discusses checkout and reset. You might need to start reading starting from branches.