Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Irina Gulina <igulina@redhat.com>
Cc: git@vger.kernel.org, Tomas Tomecek <ttomecek@redhat.com>
Subject: Re: bug - Inconsistency of git status and branch, ./git/branches and ./git/HEAD
Date: Sat, 30 Sep 2023 10:25:48 -0700	[thread overview]
Message-ID: <xmqqcyxzfu8z.fsf@gitster.g> (raw)
In-Reply-To: <CAAcHogUEtcsFcDYp16g=154CMPh_a5fmY6ABEfp9zeqEJBNb6w@mail.gmail.com> (Irina Gulina's message of "Sat, 30 Sep 2023 09:03:22 +0200")

Irina Gulina <igulina@redhat.com> writes:

>> What did you do before the bug happened? (Steps to reproduce your issue)
>> 1. create an empty directory in CLI: mkdir test_repo
>> 2. convert it to a git directory: cd test_repo & git init
>> 3. 'git status' will say you are "On branch master"
>> 4. 'git branch', 'git branch --all', or 'git branch --list' - nothing
>> will say the master branch exists. And per man pages definition the
>> branch command displays existing branches. So the question is why 'git
>> status' says "On branch master", but 'git branches' don't?

Chris gave a good answer to this most relevant question; let me
fill in one gap with others.

>> 5. check on 'ls -la ./git/branches' - it's empty

The directory is where you would configure how individual local
branches you have would behave, and it is expected to be empty if
you did not do anything special.

>> 6. check on 'ls -la ./git/refs/heads' - it's empty

You can never expect the contents of .git/refs/*  hierarchy to
correspond to any state of the refs.  If you have a history behind
your local branch 'master', i.e., after running something like

    $ git init empty && cd empty && git commit --allow-empty -m init

you can "pack" the references, i.e.,

    $ git pack-refs --all

and all the necessary data for Git to know what your branches are
and what commits they point at will be removed from .git/refs/* and
stored in different place in .git/ hierarchy.  So "there is no file
at .git/refs/heads/master" does not mean "there is no master branch",
even when we are not talking about a branch in the unborn state.

>> 7. check on 'cat ./git/HEAD' - it shows 'ref: refs/heads/master' -
>> why? if we didn't create any commit, and no branch exists?

The same comment applies to the above.  If you want to know the
state of HEAD, there are commands to do so ("git branch --list" being
one of them).  Do not expect that .git/HEAD would stay forever be
the implementation detail of what the HEAD ref points at.

  reply	other threads:[~2023-09-30 17:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-30  6:51 bug - Inconsistency of git status and branch, ./git/branches and ./git/HEAD Irina Gulina
2023-09-30  7:03 ` Irina Gulina
2023-09-30 17:25   ` Junio C Hamano [this message]
2023-09-30 11:28 ` Chris Torek
2023-09-30 11:32   ` Chris Torek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqcyxzfu8z.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=igulina@redhat.com \
    --cc=ttomecek@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox