LinuxCommandLibrary

git-show-ref

List references stored in a git repository

TLDR

Show all refs in the repository

$ git show-ref
copy

Show only heads references
$ git show-ref --branches
copy

Show only tags references
$ git show-ref --tags
copy

Verify that a given reference exists
$ git show-ref --verify [path/to/ref]
copy

SYNOPSIS

git show-ref [options…] [pattern…]

PARAMETERS

-q, --quiet
    Do not print results; implies --verify if exactly one ref matches

--verify
    Strictly verify refs exist; exit non-zero if invalid

--head
    Include the HEAD ref in output

-d, --dereference-tags[=n]
    Dereference n levels of tags (default 1); show ^{} peeled refs

-t, --tags
    Limit to tag refs only

-s, --hash[=n]
    Show only SHA-1 hash (abbrev to n digits); suppresses refname

--abbrev[=n]
    Abbreviate SHA-1 to n digits (default optimal)

--count
    Print total count of matching refs

--exclude-pattern=pattern
    Exclude refs matching shell glob pattern

--glob=pattern
    Show only refs matching shell glob pattern (overrides positional)

--points-at=object
    Show refs pointing at given object

--branches
    Synonym for --heads

--tags
    Limit to tag refs

--heads
    Limit to heads (branches)

--refs=pattern
    Synonym for --glob=pattern

DESCRIPTION

The git show-ref command displays references (refs) in a repository, such as branches, tags, and notes, along with their corresponding SHA-1 hashes. It scans the .git/refs directory and outputs lines in the format <SHA-1> <refname>.

By default, it lists all refs matching any provided patterns (or all if none given). Options allow filtering to specific ref types like heads (--heads), tags (--tags), or branches (--branches). It supports dereferencing tags to show pointed-to objects (--dereference-tags), verifying ref existence (--verify), and quiet mode (--quiet) for scripting.

This porcelain command is useful for inspecting the ref database, checking ref integrity, or generating ref lists. For more flexible formatting, prefer git for-each-ref. It handles packed refs efficiently and supports pattern matching with fnmatch-style globs.

CAVEATS

Output is ordered by refname; not suitable for parsing in scripts due to porcelain nature—use git for-each-ref instead. Patterns are fnmatch globs, not regex. Does not follow reflogs.

OUTPUT FORMAT

Each line: <SHA-1> <space> <refname>
For dereferenced tags: <SHA-1> <space> <refname>^{}

EXIT CODES

0 if all refs OK, non-zero on errors (e.g., invalid refs with --verify)

HISTORY

Introduced in Git 0.99 (2005) as a basic ref lister; evolved with options like --verify (v1.5.0) and pattern matching. Remains stable for backward compatibility.

SEE ALSO

Copied to clipboard