Re: Regarding Git and Branch Naming
- From
Philip Oakley <philipoakley@iee.email>
- Date
- Jun 26, 2020, 21:33 UTC
- Message-ID
- <6b9d76e4-68dd-8e57-f96a-318579dea6f3@iee.email>
- In-Reply-To
- <20200626203539.GA1173768@coredump.intra.peff.net>
On 26/06/2020 21:35, Jeff King wrote:
Show 33 quoted lines
> On Fri, Jun 26, 2020 at 11:33:53AM -0700, Chris Torek wrote: > >> On Fri, Jun 26, 2020 at 10:19 AM Craig H Maynard <chmaynard@me.com> wrote: >>> Does the git init command really need to create a default branch? Perhaps that step could be left to the user. >> The HEAD pseudo-ref must exist and must contain a valid OID or >> branch name. (If it does not exist, Git says that the directory >> is not a repository. Perhaps this test could be weakened, but >> that's definitely a fairly big change.) >> >> In a new, empty repository there are no valid OIDs, so HEAD must >> contain a branch name. The branch itself need not exist, but >> whatever name is in HEAD is the branch that will be created >> when the user makes the first commit. > We definitely _could_ extend HEAD to allow a "not pointing at anything" > state. Presumably for reading that would behave like the "pointing at a > branch that doesn't exist yet" case. But I think the experience it > creates for writing is not very good. I.e., I think the best we could do > is something like: > > $ git init > $ git add some-files > $ git commit -m whatever > fatal: HEAD does not point to any branch > hint: use "git checkout -b <branch>" to make commits on <branch> > > Perhaps that's not _too_ bad, but it feels a bit unfriendly (and > definitely more likely to cause backwards compatibility issues than > picking _some_ default name). There would also be a lot of corner cases > to cover and debug (e.g., "git checkout foo" moving away from the "no > branch" state should make the usual complaints if we'd have to overwrite > or modify index and untracked files). > >
A wild bikeshed question: Is HEAD itself protected as a branch name e.g. that HEAD could contain `ref: HEAD` or `ref: refs/heads/HEAD`? (or maybe the null oid
It sort of feels that we may already have some sort of protection for the first self reference - i.e. exists, but not defined (self-reference).
Philip