Re: Bug: Git sees branch as valid commit ref and works; should fail
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 5, 2024, 16:35 UTC
- Message-ID
- <xmqqy15b2aiz.fsf@gitster.g>
- In-Reply-To
- <CAFb48S8LDz4kiWsKSCBn8J=AHyQ5SVPFH4GY=z+8=DntT=PyAw@mail.gmail.com>
Matt Thompson <fortran@gmail.com> writes:
Show 13 quoted lines
> Thank you for filling out a Git bug report! > Please answer the following questions to help us understand your issue. > > What did you do before the bug happened? (Steps to reproduce your issue) > > $ git clone https://github.com/GEOS-ESM/GFDL_atmos_cubed_sphere.git fvdycore > $ cd fvdycore > $ git checkout bugfix/mathomp4/trivial-ci-commit-gcc14 > > What did you expect to happen? (Expected behavior) > > I expected a failure as there is no branch named > 'bugfix/mathomp4/trivial-ci-commit-gcc14' in the repository.
If you run
$ git for-each-ref | grep /bugfix/mathomp4/trivial-ci-commit-gcc14
I suspect you have a remote-tracking branch that matches the pattern. In such a case, "bugfix/mathomp4/trivial-ci-commit-gcc14" is a very valid way to refer to a commit to any Git command. It is handy to say "git show bugfix/mathomp4/trivial-ci-commit-gcc14", for example.
And when "git checkout" is given a commit that is not a local branch, what it did below (by the way, thanks for giving a very accurate "Actual behavior" description in your report) is very much expected behaviour, including the part that it gave a message to advise how to work on a detached HEAD.
Show 5 quoted lines
> What happened instead? (Actual behavior) > > $ git checkout bugfix/mathomp4/trivial-ci-commit-gcc14 > Note: switching to 'bugfix/mathomp4/trivial-ci-commit-gcc14'. > ...