Hacker News new | past | comments | ask | show | jobs | submit login

> HEAD is pointing to the commit you're currently looking at

HEAD pointer is pointing to the branch pointer (e.g. my-branch) which is pointing to the commit. (Except in a detached HEAD state.)

> Every time that you make a commit on `my-branch`, then both the `HEAD` and `my-branch` move to point to the new commit.

HEAD pointer keeps pointing at the my-branch pointer, and only the my-branch pointer moves to point to the new commit. But of course, when you now follow HEAD to my-branch to the commit, now you end up to the new commit.

> "detached HEAD" means that the the `HEAD` (the commit you're looking at) is not pointed at by a branch.

"Detached HEAD" means that HEAD is pointing directly to a commit, instead of pointing to a branch pointer.

You can have a detached head state, where both HEAD and the branch pointer point to the latest commit. If you use `git log --decorate`, for the latest commit it will show (HEAD, my-branch) instead of the normal (HEAD -> my-branch).




> "Detached HEAD" means that HEAD is pointing directly to a commit, instead of pointing to a branch pointer.

Ah, thanks for pointing it out, always good to learn the finer distinctions


> HEAD pointer is pointing to the branch pointer (e.g. my-branch) which is pointing to the commit. (Except in a detached HEAD state.)

Yes! Here[1] is a nice picture about from Git Reset Demystified article. You can also see is in the following `git branch -a` output,

    * main
      remotes/origin/HEAD -> origin/main
      remotes/origin/main

[1] https://git-scm.com/book/en/v2/Git-Tools-Reset-Demystified




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: