Re: bug - Inconsistency of git status and branch, ./git/branches and ./git/HEAD

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Sep 30, 2023 at 4:06 AM Irina Gulina <igulina@xxxxxxxxxx> wrote:
> ... So the question is why 'git
> status' says "On branch master", but 'git branches' don't?

Although this seems weird, it is in fact normal.

This situation in Git -- where you are on a branch that does not exist --
is called an "orphan branch" or an "unborn branch" (which term is used
depends on which bit of documentation you read).

The unborn / orphan current branch becomes "born" (begins to exist)
once you make a commit while on it. If you move to a different branch,
the unborn branch never comes into existence.

A new, empty repository cannot have any branches, because a branch
is defined as "the latest commit that is on the branch" (this definition is
unsatisfyingly circular, but that too is what it is). With no commits in the
repository, no branches can exist. Yet you must be "on" some branch.
Hence the existence of unborn branches, which are born when you
make a new commit. That first commit creates the first branch name
as well as the first commit.

Creating a new commit while on an unborn branch causes the new
commit to have no parent commit. This, too, is normal and natural
in a new empty repository, but it holds true for the situation in which
you create a new unborn / orphan branch using `git checkout --orphan`
or `git switch --orphan` while in a non-empty repository. You don't
normally want to do this, but it's sometimes useful for some special
oddball cases.

Chris




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux