LinuxCommandLibrary

git-for-each-ref

Output information on each reference with custom formatting

TLDR

List all refs

$ git for-each-ref
copy
List branches
$ git for-each-ref refs/heads
copy
List tags
$ git for-each-ref refs/tags
copy
Custom format
$ git for-each-ref --format='%(refname:short) %(objectname:short)' refs/heads
copy
Sort by date
$ git for-each-ref --sort=-committerdate refs/heads
copy
Show latest N refs
$ git for-each-ref --count=[10] --sort=-committerdate refs/heads
copy

SYNOPSIS

git for-each-ref [options] [patterns...]

DESCRIPTION

git for-each-ref is a plumbing command that outputs detailed information about Git references (branches, tags, remote branches) in a highly customizable format. It serves as the foundation for many higher-level Git commands and scripts that need to process repository references.
The format string syntax supports field extraction using %(fieldname) placeholders, with available fields including refname, objecttype, objectname, author, committer, and many others. Sorting capabilities enable ordering references by any field, with support for reverse sorting using a minus prefix.
This command is primarily used in scripts and Git aliases rather than direct user interaction. The filtering options (--merged, --no-merged, --points-at) provide powerful selection mechanisms for finding references matching specific criteria.

PARAMETERS

--format format

Output format string.
--sort key
Sort by key.
--count n
Limit output count.
--points-at object
Show refs pointing to object.
--merged commit
Show refs merged into commit.
--no-merged commit
Show refs not merged.

SEE ALSO

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community