Synopsis
git symbolic-ref [--short] <name> [<ref>]
git symbolic-ref --delete <name>
Description
The git symbolic-ref command manipulates symbolic refs — refs that point at another ref instead of a commit. The most familiar example is HEAD: when you're on branch main, HEAD is a symbolic ref pointing at refs/heads/main. Other examples include the default branch indicator on remotes (refs/remotes/origin/HEAD).
In day-to-day use, git symbolic-ref integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git symbolic-ref --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.
Understanding how git symbolic-ref interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git symbolic-ref's side effects helps avoid all three.
When to Use
Use this when you need to switch HEAD without touching the working tree (e.g., during a custom migration), or when scripting around the default-branch concept. Most users only ever read symbolic refs via git rev-parse --abbrev-ref HEAD.
Common Options
| Option | Description |
|---|---|
--short | Print the short name (e.g. main). |
--delete | Delete the symbolic ref. |
--quiet | Don't print error if ref is missing. |
-m <reason> | Reflog reason for changes. |
Examples
git symbolic-ref HEAD
# refs/heads/main
git symbolic-ref --short HEAD
# main
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
# Set the default branch indicator on origin
git symbolic-ref HEAD refs/heads/develop
# Switch HEAD without touching working tree (advanced!)
Common Mistakes
Switching HEAD via symbolic-ref doesn't update the working tree — files won't change. Use git switch for the everyday case. Setting origin/HEAD incorrectly confuses tools that look up the default branch.
Related Commands
git update-ref, git switch, git rev-parse, git remote set-head