git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] revisions: add @{default} shorthand for default branch

From
Junio C Hamano <gitster@pobox.com>
Date
Jan 30, 2026, 16:42 UTC
Message-ID
<xmqq4io3831o.fsf@gitster.g>
In-Reply-To
<20260130105954.59636-1-haraldnordgren@gmail.com>
Harald Nordgren <haraldnordgren@gmail.com> writes:
Show 9 quoted lines
>> 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
>
> I have never heard about anyone doing that. Isn't it more expected that
> people keep whatever branch is on the remote? But regardless, I hope
> there is a way to still make @{default} map to whatever your renamed your
> default branch to.

But then that is what "default" is, isn't it? The "default" branch is what "git init" would create unless it is told otherwise. The 'main' branch that the above example user renamed to to use because they did not like the name 'master' is their primary branch that is not the "default".

In a sense, I think what you are after _is_ "what the user considers the primary branch in this repository". How init.defaultBranch is configured in their global (i.e., per-user) configuration file may be a good hint to help answering the question, but not necessarily.

For those who follow the naming the upstream decided to use in cloned repositories, init.defaultBranch is probably the last thing you want to take as a hint, as these people decided to _ignore_ the preference of their own and instead to follow what upstream uses. For that, refs/remotes/origin/HEAD would be a lot more stronger hint. If they call their primary branch 'trunk', these people would want to call theirs 'trunk'. And for that, these people would not do anything with init.defaultBranch.

Show 5 quoted lines
>     git checkout $(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
>
> That's uneccessary overhead, that could now be replaced with:
>
>     git checkout @{default}

That mirrors what I wrote in the previous paragraph. Those who follow the naming the upstream uses, refs/remotes/$remote/HEAD (here, "origin" may not be the default remote) would be a better hint than init.defaultBranch so calling it @{default} is misleading.

I am not good at naming things, so instead of calling it @{primary} let's call it @{dumbo}. With the realization that what branch refs/remotes/$remote/HEAD points at is a good source of hint, I actually think $branch@{dumbo} does make sense, and @{dumbo} should be a short-hand for $branch@{dumbo} where the name of the current branch is substituted for $branch (i.e. similar to @{push}, I suppose). As you may be interacting with two sets of branches that go to two different remotes.

In any case, it is very different from what you implemented as the @{default} in your patch.

Thanks.
Previous: Harald NordgrenNext: Harald Nordgren
Message 5 of 32 in “revisions: add @{default} shorthand for default branch”
  1. revisions: add @{default} shorthand for default branchHarald Nordgren via GitGitGadget, Jan 29, 2026
  2. Junio C HamanoJan 29, 2026
  3. Harald NordgrenJan 30, 2026
  4. Harald NordgrenJan 30, 2026
  5. Junio C HamanoJan 30, 2026
  6. Harald NordgrenJan 30, 2026
  7. Junio C HamanoJan 30, 2026
  8. Harald NordgrenJan 31, 2026
  9. Junio C HamanoJan 31, 2026
  10. Harald NordgrenJan 31, 2026
  11. Harald NordgrenJan 31, 2026
  12. Junio C HamanoFeb 2, 2026
  13. Harald NordgrenFeb 2, 2026
  14. Phillip WoodFeb 2, 2026
  15. Harald NordgrenFeb 2, 2026
  16. D. Ben KnobleFeb 2, 2026
  17. Harald NordgrenFeb 2, 2026
  18. Kristoffer HaugsbakkFeb 2, 2026
  19. Ben KnobleFeb 2, 2026
  20. Harald NordgrenFeb 2, 2026
  21. Junio C HamanoFeb 2, 2026
  22. Ben KnobleFeb 2, 2026
  23. Harald NordgrenFeb 2, 2026
  24. Junio C HamanoFeb 2, 2026
  25. Harald NordgrenFeb 2, 2026
  26. Harald NordgrenFeb 3, 2026
  27. Phillip WoodFeb 3, 2026
  28. Junio C HamanoFeb 2, 2026
  29. revisions: add @{default} shorthand for default branchHarald Nordgren via GitGitGadget, Jan 30, 2026
  30. Kristoffer HaugsbakkJan 30, 2026
  31. revisions: add @{primary} shorthand for primary branchHarald Nordgren via GitGitGadget, Jan 30, 2026
  32. revisions: add @{primary} shorthand for primary branchHarald Nordgren via GitGitGadget, Jan 31, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.