5

I've been getting familiar with creating, merging and deleting branches. I like to know where I am so I don't commit work into the wrong branch. I use git branch -a to see which branches I have. I think the asterix * shows which branch I'm currently on. What does it mean when I get:

* (no branch)
master
origin/HEAD

Because when I $git checkout mybranch I expect to see

* mybranch
master
origin/HEAD

Neofizz
  • 53
  • 5

2 Answers2

4

The git checkout man page does mention, for the branch name argument:

<branch>

Branch to checkout;

  • if it refers to a branch (i.e., a name that, when prepended with "refs/heads/", is a valid ref), then that branch is checked out.
  • Otherwise, if it refers to a valid commit, your HEAD becomes "detached" and you are no longer on any branch.

So instead of having checked out a branch name, you must have checked out a tag name (valid commit), making your HEAD a detached one.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • You were absolutely right, I had a detached head. This was an unknown scenario for me which I over looked in my study of branches. I found all the information I need to fix it. Thanks for pointing me in the right direction! – Neofizz Jun 15 '10 at 08:53
1

It doesn't look like you have a branch called mybranch. If you want to create a branch that points to the current head, use git branch foo.

If you want one that points to another ref, use git checkout -b newbranch <ref>

Alex Budovski
  • 17,947
  • 6
  • 53
  • 58