Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Development Tools Git Branches and Merging Branches Branches Behind the Scenes

Branches Behind the Scenes

I really appreciate this lesson -- very useful!

One quiz question is this:

If the below commands were run in order, what would the output of cat .git/HEAD be?

$ git checkout master
$ git log
commit 21428a2eee8e55becb6da879228446746ad6f1a8 (HEAD -> master)
Author: Jay McGavren <me@example.com>
Date:   Tue Sep 25 08:34:12 2018 -0700

    Add villain
$ git checkout 21428a2eee8e55becb6da879228446746ad6f1a8
$ cat .git/HEAD

I'm curious, because my understanding of this is that checking out the latest commit sounds to me like not changing anything, but in fact, it returns this: You are in 'detached HEAD' state.

The answer doesn't change: the output results are the SHA, and the answer says:

Well done! If an individual commit is checked out, then HEAD points directly to that commit, not a branch.

My questions:

1) Why is it that the output of $ git log -1 --decorate doesn't change, whether or not I run $ git checkout 21428 ?

2) If that doesn't change, then what exactly does?

My own answer to this is that, this just means that HEAD is pointing to the branch, and not to an individual commit. Is this true?

Thank you thank you thank you!

1 Answer

Jay McGavren
STAFF
Jay McGavren
Treehouse Teacher

I tested this, and it looks like the output of git log --decorate does change. The "decoration" showing where branches are pointing changes from (HEAD -> master) (showing that HEAD points to the master branch) to (HEAD, master) (showing that HEAD points to the same commit as master, but does not point to master).

The important difference between git checkout master and git checkout 21428a is this: if master is checked out, and you make a commit, the master branch will be updated to point to that new commit. If a specific commit is checked out, and you make a commit, no branches will be updated.