I often do git symbolic-ref HEAD refs/heads/my_branch to move to another branch without touching the index or worktree.
That's ... an unusual work-flow. :-) (It does work, and if that's what you want to achieve, that's OK.)
Is there a "porcelain" command or series of commands that does exactly the same thing?
No—at least, not in general.
HEAD
is either tied to a branch name (normal state, "on" a branch), or to a commit hash ID ("detached HEAD"). In the normal state, the only porcelain (non-plumbing) way to put a new branch name into HEAD
is to use the branch-switching commands: git checkout
or, since Git 2.23, git switch
. Both of these insist on updating the index and work-tree to whatever extent is required. Sometimes that will be a very small amount of updating, and might be useful to you.
In the detached-HEAD state, if the new state is also to be detached, git reset --soft
will do the job—but in that particular case you need to use git update-ref
rather than git symbolic-ref
when doing the work via a plumbing command. In particular, git reset hash
leaves you in detached-HEAD state.
Using git reset
when in attached-HEAD state will move the target of HEAD
—the branch to which HEAD
is attached—to the selected commit, while git symbolic-ref
won't.