All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH] revisions: add @{default} shorthand for default branch
Date: Thu, 29 Jan 2026 12:23:34 -0800	[thread overview]
Message-ID: <xmqq1pj8b22h.fsf@gitster.g> (raw)
In-Reply-To: <pull.2183.git.git.1769700352081.gitgitgadget@gmail.com> (Harald Nordgren via GitGitGadget's message of "Thu, 29 Jan 2026 15:25:52 +0000")

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Git already has shorthands like @{upstream} and @{push} to refer to
> tracking branches, but there is no convenient way to refer to the
> default branch of a repository (typically "main" or "master").
>
> Users often want to switch to the default branch regardless of its
> name, especially when working across repositories with different
> default branch names. Currently they must either hardcode the branch
> name or query it via configuration, which is cumbersome.
>
> Add a new @{default} shorthand that resolves to the default branch
> as determined by init.defaultBranch (or falls back to "main" or
> "master" depending on Git version). This allows users to write:
>
>   git checkout @{default}
>
> instead of having to know or look up the default branch name.
>
> The implementation follows the same pattern as @{upstream} and @{push},
> using a new branch_get_default() function that queries the default
> branch name and verifies it exists in the repository.

But @{upstream} and @{push} are inherently very different from what
you are adding, aren't they?  Asking for topic1@{upstream} and
topic2@{upstream} makes quite a lot of sense, because the meaning of
@{upstream} depends on "which branch's upstream are you talking
about???".  But I suspect that asking for topic1@{default} and
expect it would be different from topic2@{default} is nonsense, as
"the default" is not per branch but is an attribute of a repository.
In other words, <branch>@{default} may by itself be a nonsense
query.  Are you rejecting a non-empty <branch> that may appear
before @{default} as an error?

After cloning an upstream project, those who dislike the local
branch name 'master' often rename it to something else, like 

    $ git branch -m master main

and be happy, without configuring "init.defaultbranch".  After all,
that configuration variable affects newly created repositories, so
after renaming 'master' to 'main', it is too late anyway.  In such a
repository, if you say @{default}, what should happen?  As 'master'
branch no longer exist, even though it is the @{default}, should it
error out?  Does your implementation error out?

Also I do not quite see how this would be useful in practice.  Given
that the names of local branches are under control of the local end
user and not upstream projects, I would imagine that the primary
branch used by a user is of per-user nature, not per repository.  In
other words, instead of having to do "git branch -m" after cloning,
you may do "git config --global init.defaultBranch" just once and
keep using the same default name.  Under that condition, "can I ask
what default branch name this repository uses, so that I can work on
that branch" is rarely needed, if you are writing a script to use in
many of your repositories, isn't it?

So, I am not sure.  I wouldn't mind too terribly if <name>@{default}
is rejected, but I do not imagine many people using it.

  reply	other threads:[~2026-01-29 20:23 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-29 15:25 [PATCH] revisions: add @{default} shorthand for default branch Harald Nordgren via GitGitGadget
2026-01-29 20:23 ` Junio C Hamano [this message]
2026-01-30 10:59   ` Harald Nordgren
2026-01-30 11:12     ` Harald Nordgren
2026-01-30 16:42     ` Junio C Hamano
2026-01-30 20:58       ` Harald Nordgren
2026-01-30 21:56         ` Junio C Hamano
2026-01-31  0:09           ` Harald Nordgren
2026-01-31 19:16       ` Junio C Hamano
2026-01-31 20:22         ` Harald Nordgren
2026-01-31 20:55           ` Harald Nordgren
2026-02-02 12:32             ` Junio C Hamano
2026-02-02 15:30               ` Harald Nordgren
2026-02-02  9:37           ` Phillip Wood
2026-02-02 10:14             ` Harald Nordgren
2026-02-02 19:40               ` D. Ben Knoble
2026-02-02 21:19                 ` Harald Nordgren
2026-02-02 21:53                   ` Kristoffer Haugsbakk
2026-02-02 22:17                   ` Ben Knoble
2026-02-02 22:54                     ` Harald Nordgren
2026-02-02 21:33                 ` Junio C Hamano
2026-02-02 22:16                   ` Ben Knoble
2026-02-02 23:03                 ` Harald Nordgren
2026-02-02 21:44               ` Junio C Hamano
2026-02-02 22:56                 ` Harald Nordgren
2026-02-03 11:18                   ` Harald Nordgren
2026-02-03 14:38               ` Phillip Wood
2026-02-02 22:28             ` Junio C Hamano
2026-01-30 13:26 ` [PATCH v2] " Harald Nordgren via GitGitGadget
2026-01-30 16:54   ` Kristoffer Haugsbakk
2026-01-30 20:45   ` [PATCH v3] revisions: add @{primary} shorthand for primary branch Harald Nordgren via GitGitGadget
2026-01-31  0:06     ` [PATCH v4] " Harald Nordgren via GitGitGadget

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=xmqq1pj8b22h.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=haraldnordgren@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.