If I run git checkout --orphan my_new_branch
, then .git/HEAD
points to a ref that does not (yet) exist.
git checkout --orphan my_new_branch
Switched to a new branch 'my_new_branch'
cat .git/HEAD
ref: refs/heads/my_new_branch
git show-ref refs/heads/my_new_branch
# No output
ls .git/refs/heads/my_new_branch
ls: cannot access '.git/refs/heads/my_new_branch': No such file or directory
Mostly out of curiosity, I tried to replicate this state using update-ref
and symbolic-ref
, but git
seems to disallow this:
git update-ref HEAD 'refs/heads/my_new_branch'
fatal: refs/heads/my_new_branch: not a valid SHA1
git symbolic-ref HEAD 'ref: refs/heads/my_new_branch'
fatal: Refusing to point HEAD outside of refs/
Is there some other plumbing command invocation that can explicitly move HEAD to point at a non-existent ref, without all the other side effects of git checkout --orphan
?
I am aware that I can just do echo "ref: refs/heads/my_new_branch" > .git/HEAD
, but I am curious to learn about whether directly writing to the file is the only approach.
Output of git -v
, in case the behavior is version-dependent:
git version 2.47.0
4