1

Possible Duplicate:
HEAD and ORIG_HEAD in Git

By default we see two branches in git:

origin/master origin/HEAD 

I wonder, what is head used for?

5

2 Answers 2

1

HEAD is a a symbolic reference (similar to a symbolic link) that points to the branch you're on. You can get the reference it points to using git symbolic-ref HEAD. If you switch branches (e.g. git checkout branch1), HEAD will point to that. This is stored in a file in .git as .git/HEAD.

master is a local branch that you can work on. It's usually the default if you clone a repository or start a fresh one.

origin/master is the location of the master branch on the remote called origin.

Sign up to request clarification or add additional context in comments.

4 Comments

HEAD in a local repository does not always refer to a branch, it more specifically refers to the currently checked-out branch. You can enter a detached HEAD state where HEAD no longer refers to any branch.
Correct. I didn't mention that because it's not that common and the OP's question suggested her lack of experience with git.
It's funny though, even the documentation itself says that HEAD refers to the current branch. The documentation is wrong :/.
That is in some ways true. Even in a detached head state, you are somewhere and that can be referred to as a head (which is what git says for branch) but yeah, you're right. Send them a pull request?
1

It's a pointer to the current commit.

Since it represents a commit you can can use it with most of git's commands.

Examples:

Show the latest commit with it's diff:

git show HEAD 

Interactively rebase to the commit before the latest:

git rebase -i HEAD^ 

2 Comments

HEAD does not refer to your current branch, it refers to the currently checked-out commit. You can check-out a commit directly, which puts you in a "detached HEAD" state (detached from a branch). If you checkout HEAD~10 for example, HEAD will then refer to a commit that's 10 commits behind your previous branch.
Thanks @Cupcake, I've updated my answer appropriately.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.