The second one with (no branch) is shown when you are not on any branch at all. It often is used when you are sightseeing the tree of a tagged version, e.g. after running git checkout v1.8.3 or something like that.

To find out what the current branch is, casual/careless users may have scripted around git branch, which is wrong. We actively discourage against use of any Porcelain command, including git branch, in scripts, because the output from the command is subject to change to help human consumption use case.And in fact, since release 1.8.3, the output when you are not on any branch, has become something like this:$ git checkout v1.8.3$ git branch* (detached from v1.8.3) master next

in order to give you (as a human consumer) a better information. If your script depended on the exact phrasing from git branch, e.g.

The right way to programatically find the name of the current branch, if any, is not to use the Porcelain command git branch that is meant for the human consumption, but to use a plumbing command git symbolic-ref instead:

if branch=$(git symbolic-ref --short -q HEAD)then echo on branch $branchelse echo not on any branchfi