Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where am I? * (no branch)

Tags:

git

branch

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

like image 518
Neofizz Avatar asked Apr 30 '10 09:04

Neofizz


People also ask

What does no branch mean?

"Not currently on any branch" means you have a detached head, i.e. your HEAD pointer is directly referencing a commit instead of symbolically pointing at the name of a branch. You can get into this situation by checking out a commit by SHA1, or when you're in the middle of a rebase, or when a merge fails.

How do I find my local remote branch?

just need to run git fetch , which will retrieve all branches and updates, and after that, run git checkout <branch> which will create a local copy of the branch because all branches are already loaded in your system.

How do I get my detached head back?

To save changes committed in a detached HEAD state, you first need to create a new branch. Continuing from the scenario described above, you create a new branch called temp-branch . As soon as you make the branch and check out to it, the HEAD is no longer detached.


1 Answers

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.

like image 52
VonC Avatar answered Sep 18 '22 12:09

VonC