git-show-ref
List references stored in a git repository
TLDR
Show all refs in the repository
Show only heads references
Show only tags references
Verify that a given reference exists
SYNOPSIS
git show-ref [--head] [--dereference] [--abbrev[=<n>]] [--hash] [--exclude-existing[=<pattern>]] [--verify] [--quiet] [--no-warn] [--print-names] [<pattern>...]
PARAMETERS
--head
Show the HEAD reference, if it exists, even if it does not match a pattern.
-d | --dereference
Dereference tags into object IDs. This shows the object ID that a tag points to, in addition to the tag itself.
-s | --sha1
Only show the SHA-1 hash, not the full reference name. (This is often the default behavior without --print-names).
--verify
Verify that each ref passed as a pattern exists and is a valid object. Exits with non-zero status if any ref is not found or invalid.
-q | --quiet
Do not print any error messages or warnings to stderr, useful when used with --verify.
--no-warn
Suppress warnings when a specified pattern does not match any reference.
--print-names
Show the names of the refs even if they are not matching a pattern. (This implies --verify if patterns are given).
--hash
Only show the hash, not the name (opposite of --print-names). Implies --abbrev=40 unless --abbrev is specified.
--abbrev[=<n>]
Abbreviate the object names (SHA-1 hashes) to <n> characters, or the default length if <n> is omitted.
--exclude-existing[=<pattern>]
Only show refs that do not exist locally. If a pattern is provided, it must match the refname exactly for it to be excluded.
--no-exclude-existing
Do not exclude existing refs. Useful for overriding a global config or previous --exclude-existing.
<pattern>...
Optional patterns to filter the references. Only refs matching any of the given patterns will be shown. Patterns typically start with 'refs/heads/', 'refs/tags/', 'refs/remotes/', etc.
DESCRIPTION
The git show-ref command is a low-level utility used to display the references (branches, tags, remote-tracking branches, etc.) and their corresponding object IDs (SHA-1 hashes) in a Git repository. It's primarily designed for scripting and internal Git operations, offering a raw view of the repository's reference structure.
By default, it lists all references found under refs/, including loose references (files) and packed references (in .git/packed-refs). The output format is typically a SHA-1 hash followed by the full reference name.
Unlike higher-level commands like git branch or git tag, git show-ref provides direct access to the underlying reference data, making it suitable for tasks that require parsing reference information without additional formatting or filtering. It can be used to check for the existence of specific references or to retrieve their associated commit, tag, or tree IDs.
CAVEATS
git show-ref only displays references known locally by the repository. It does not communicate with remote repositories to fetch or update reference information; for remote references, consider using git ls-remote.
The output format is highly stable, making it ideal for parsing in scripts, but generally less human-readable than higher-level commands like git branch -v.
Without specific patterns, it can list a very large number of references in a busy repository, which might be slow.
OUTPUT FORMAT
By default, git show-ref outputs lines in the format:
<SHA-1> <refname>
For example:
a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 refs/heads/main
When --dereference is used, for an annotated tag, a second line is added with the object it points to:
a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0 refs/tags/v1.0
b0a9f8e7d6c5b4a3e2d1c0b9a8f7e6d5c4b3a210 refs/tags/v1.0^{} (where the second hash is the object the tag points to).
PATTERN MATCHING
Patterns provided to git show-ref are typically full or partial reference names, often starting with standard Git prefixes like refs/heads/, refs/tags/, refs/remotes/, etc. For example, git show-ref refs/heads/ will list all local branches. Patterns can also be full refnames like refs/heads/main. The patterns are implicitly anchored to the beginning, meaning 'foo' will match 'refs/heads/foo' but not 'refs/heads/foobar'.
HISTORY
git show-ref has been a core part of Git since its early days, serving as a fundamental building block for scripting and internal operations that require direct access to Git's reference infrastructure. It provides a simple, consistent interface to list and verify references, complementing higher-level commands that offer more user-friendly interactions. Its design prioritizes machine readability and robustness, making it a reliable tool for automating Git workflows.
SEE ALSO
git-branch(1), git-tag(1), git-for-each-ref(1), git-ls-remote(1), git-rev-parse(1)