The following shell code correctly creates a chain of symbolic references
git symbolic-ref "first" "refs/heads/master"
git symbolic-ref "second" "first"
git symbolic-ref "nested/third" "second"
git symbolic-ref "refs/heads/fourth" "nested/third"
And the following shell code correctly resolves the latest created symbolic reference to the tip of master.
git show-ref "refs/heads/fourth"
None of these use cases are described in the official documentation (git-symbolic-ref doc, git-show-ref doc).
However, the following doesn't work
git check-ref-format --print "first"
So, my questions are:
refs/heads
directory ?"first"
, does this mean that it's not recommended to create a symbolic reference at the same level than "HEAD"
? Or maybe this command is not intended to deal with symbolic links ?My intent is to get a clear understanding of what is being supported and that I'm not working around anything or benefiting from a bug.
I've eventually posted this question to the git development mailing list.
Junio C Hamano, the lead git maintainer (+8700 commits) provided me with the following answers.
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.