How HEAD points at a branch instead of a SHA.
git symbolic-ref reads or writes refs that point at other refs instead of at a SHA. The canonical example is HEAD, which usually points at refs/heads/<current-branch> rather than directly at a commit.
A symbolic ref is a one-line file containing ref: refs/.... Reading resolves one hop; writing replaces the target. This is exactly how git switch <branch> re-aims HEAD without moving any commit.
git symbolic-ref [-m <reason>] <name> <ref> # write
git symbolic-ref [-q] [--short] <name> # read
git symbolic-ref --delete [-q] <name> # delete
Reads exit non-zero (and may print to stderr) if <name> is not symbolic.| Flag | What it does |
|---|---|
--short | Strip refs/heads/ from the read result -- e.g. main instead of refs/heads/main. |
-d, --delete | ⚠️ Remove the symbolic ref entirely (HEAD-less repo if you delete HEAD). |
-q, --quiet | Suppress error output when <name> is not symbolic; rely on exit code. |
-m <reason> | Reflog message recorded with the update -- HEAD's reflog is the audit trail. |
git symbolic-ref --short HEAD.refs/remotes/origin/HEAD after the upstream default branch is renamed.git symbolic-ref --short HEADgit symbolic-ref HEAD refs/heads/featuregit symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/maingit symbolic-ref -m 'switch to release' HEAD refs/heads/releasegit symbolic-ref --short HEAD over parsing git branch --show-current in legacy scripts.-q plus exit-code checks to handle detached HEAD gracefully.-m whenever you write HEAD so the reflog records why.Hit each option, then Check answers. Score is recorded; Next is always open.