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

What’s the intended/reasonable usage patterns for symrefs?

From
Kristoffer Haugsbakk <code@khaugsbakk.name>
Date
Oct 13, 2024, 19:57 UTC
Message-ID
<174f3704-6319-48f9-955e-b36a25836e3d@app.fastmail.com>
This was posted in 2011:
“What's the definition of a valid Git symbolic reference?”
https://lore.kernel.org/git/AANLkTinsJkzYggMtNrLRv-qNxRncrXSe6A46Z=d8xkw7@mail.gmail.com/
And the answer said that:
Show 27 quoted lines
> Emeric Fermas <emeric.fermas@gmail.com> writes:
>
> >  Once again, by reading at the code I can understand how those commands
> > currently work. What I'm trying to achieve is to understand what
> > should be their recommended usage.
>
> There are only two valid kinds of symrefs right now:
>
>  - .git/HEAD, pointing at somewhere under refs/heads/ hierarchy;
>
>  - .git/refs/remotes/<some remote name>/HEAD, pointing at somewhere under
>    refs/remotes/<the same remote name>/ hierarchy.
>
> The code may be prepared to resolve recursive symrefs, symrefs other than
> the above two kinds, symrefs that point at elsewhere, but all of them are
> outside of the design scope of what the mechanism was intended to support.
> What the code do to them (without crashing) is not the design, but simply
> an undefined behaviour.
>
> This won't change very much if we decide to reorganize the remote tracking
> hierarchies in 1.8.0.  The former won't change at all, and the latter will
> start pointing at refs/remotes/<the same remote name>/heads hierarchy
> instead.
>
> I vaguely recall tg abused the symref mechanism to point .git/HEAD at
> funny locations; it may still be doing so, and if that is the case we
> should extend the above list to cover that usage.
https://lore.kernel.org/git/7vsjvpq0jk.fsf@alter.siamese.dyndns.org/

This was motivated by a StackOverflow[1] question/thread. Which should maybe get an update if this thread reveals some new information.

🔗 1: https://stackoverflow.com/a/5000668/1725151
This seems overly restrictive for this day and age though? No?
I only know that
1. Symref manipulation is a plumbing command
2. That means that you can do weird stuff without getting slapped on the
   wrist
3. The plumbing man pages sometimes feel inert, like they either don’t
   fit into a greater whole or they don’t want to tell you
   (git-rev-list(1) is apparently the plumbing dual to git-log(1) but
   all I can see is some references at the bottom like “see also the
   porcelain git-log(1)” (in a 1200 line page)

In conclusion: I might end up doing things which I’m not really supposed to. Because these commands are unopinionated.

What I’ve done lately that might give *weird* results:
• Create a one-level symref (one-level “because it’s short”)
• Then you might get “ambigious” warnings if some branch ref has the
  same name
But what seems fine so far:
• Create a `refs/heads/<symref>` which points to a remote-tracking branch
This is so that I can
• Have a short name for some long-living branches (sometimes they live
  longer than we would have planned for)
• So that I can rebase and set upstream on the remote-tracking branch.
  That way I don’t need to maintain a branch which just follows the
  remote-tracking one

Is this okay? And what can you reasonably do in general terms with symrefs?

Just as an example of something that is probably not fine: I’ve read that symrefs are dereferenced only to a depth of four. And then you don’t want to create some contraption which relies on many levels of dereferencing.

Thanks!
-- 
Kristoffer
Next: Patrick Steinhardt
Message 1 of 5 in “What’s the intended/reasonable usage patterns for symrefs?”
  1. Kristoffer HaugsbakkOct 13, 2024
  2. Patrick SteinhardtOct 14, 2024
  3. Kristoffer HaugsbakkOct 16, 2024
  4. Kristoffer HaugsbakkNov 4, 2024
  5. Kristoffer HaugsbakkJun 20, 2025

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.