How to practice getting into and out of a detached HEAD state via command line – 096

Yesterday’s tip went over the visualization of what happens when you are in a detached head state. Today’s tip now applies it to the command line.

Suppose you’ve initialized a git repository using the bash script from a previous tip. I’ve only used 3 files to be concise.

And you’ve did a git checkout <previous-commit-ID> to get into a state similar to Stephen King’s IT trailer. (don’t worry no videos here*)

detached head state

Remember your training.

Optional: let’s do a git reflog to get that sense of security that all of our commits are still there. Even though the file 3 commit is “gone”, the reflog verifies all is well.

git reflog showing all history

Now let’s get out of that detached head state by doing a git checkout master. Previously, I would have done git checkout <last-commit-ID> and freaked out that I was still in a detached head state.

head back to pointing at master

And now all is good in the world again. We see master in blue. We see all 3 previous commits. And our git status isn’t like something from a Stephen King movie.

*As many of you know, I used to be a professional clown. Clowns don’t scare me, but wow seriously that trailer is scary! 

One thought on “How to practice getting into and out of a detached HEAD state via command line – 096

Leave a comment