Re: [PATCH] revisions: add @{default} shorthand for default branch
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Feb 3, 2026, 14:38 UTC
- Message-ID
- <9120dbf3-f10f-4333-aa70-f24835d7ef02@gmail.com>
- In-Reply-To
- <20260202101445.13790-1-haraldnordgren@gmail.com>
On 02/02/2026 10:14, Harald Nordgren wrote:
>> I don't really understand what you're trying to achieve and I'm not sure >> if the suggestion above is a good idea but it might help understand what >> it is you're trying to do.
>
Show 18 quoted lines
> I want a shorthand so that when in any of these repos, I'm switching to the
> default branch, I simply have to run
>
> git switch @{primary}
>
> and I would end up with
>
> 99designs/gqlgen
> Switched to branch 'master'
>
> amplitude/experiment-react-native-client
> Switched to branch 'main'
>
> Antonboom/testifylint
> Switched to branch 'main'
>
> cli/cli
> Switched to branch 'trunk'I think I understand now. That sounds tricky to do in the general case because we don't know what the remote is called. "origin" and "upstream" are popular choices but the user can choose any name they want when they run "git clone" (or rename the remote after they clone). If there is only one remote then its simple because there is only one choice. It's also simple if there are multiple remotes and they all use the same default branch name and refspecs. If remote.pushDefault is set we can probably rule that remote out. If there's a branch checked out with an upstream set we could use that remote but there's no guarantee that's the remote the user wants. I don't think there's a robust way to determine the remote the user wants in the general case.
With the "@{local}" thing I suggested yesterday the user would have to name the remote which makes everything well defined but I think you want to avoid having to do that.
Thanks
Phillip