Re: [PATCH v2] revisions: add @{default} shorthand for default branch
- From
- Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
- Date
- Jan 30, 2026, 16:54 UTC
- Message-ID
- <7b62316f-a30a-4895-808d-baa20be0f3af@app.fastmail.com>
- In-Reply-To
- <pull.2183.v2.git.git.1769779599196.gitgitgadget@gmail.com>
On Fri, Jan 30, 2026, at 14:26, Harald Nordgren via GitGitGadget wrote:
Show 5 quoted lines
> 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").I don’t use a lot of different repositories. But for the two I do use I use `origin`. (Really `o` since I name the regular remote `o`.) Most of the time I do not need to have the main *branch* as a branch. I am not working on the main branch. Using the remote-tracking branch directly is more convenient.
> 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.
*Query it* sounds like git-config(1). I have found `git var GIT_DEFAULT_BRANCH` useful for when I want to answer a question without hardcodig `main` or `master`.
Show 16 quoted lines
>
> 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.
>
> Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
> ---
>[snip]