'\" t .\" Title: git-for-each-ref .\" Author: [FIXME: author] [see http://www.docbook.org/tdg5/en/html/author] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 2026-06-29 .\" Manual: Git Manual .\" Source: Git 2.55.0 .\" Language: English .\" .TH "GIT\-FOR\-EACH\-REF" "1" "2026\-06\-29" "Git 2\&.55\&.0" "Git Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" git-for-each-ref \- Output information on each ref .SH "SYNOPSIS" .sp .nf \fBgit\fR \fBfor\-each\-ref\fR [\fB\-\-count=\fR\fI\fR] [\fB\-\-shell\fR|\fB\-\-perl\fR|\fB\-\-python\fR|\fB\-\-tcl\fR] [(\fB\-\-sort=\fR\fI\fR)\&...] [\fB\-\-format=\fR\fI\fR] [\fB\-\-include\-root\-refs\fR] [\fB\-\-points\-at=\fR\fI\fR] [\fB\-\-merged\fR[\fB=\fR\fI\fR]] [\fB\-\-no\-merged\fR[\fB=\fR\fI\fR]] [\fB\-\-contains\fR[\fB=\fR\fI\fR]] [\fB\-\-no\-contains\fR[\fB=\fR\fI\fR]] [(\fB\-\-exclude=\fR\fI\fR)\&...] [\fB\-\-start\-after=\fR\fI\fR] [ \fB\-\-stdin\fR | (\fI\fR\fB\&...\fR)] .fi .sp .SH "DESCRIPTION" .sp Iterate over all refs that match \fI\fR and show them according to the given \fI\fR, after sorting them according to the given set of \fI\fR\&. If \fI\fR is given, stop after showing that many refs\&. The interpolated values in \fI\fR can optionally be quoted as string literals in the specified host language allowing their direct evaluation in that language\&. .SH "OPTIONS" .PP \fI\fR\&.\&.\&. .RS 4 If one or more \fI\fR parameters are given, only refs are shown that match against at least one pattern, either using \fBfnmatch\fR(3) or literally, in the latter case matching completely or from the beginning up to a slash\&. .RE .PP \fB\-\-stdin\fR .RS 4 The list of patterns is read from standard input instead of from the argument list\&. .RE .PP \fB\-\-count=\fR\fI\fR .RS 4 Stop after showing \fI\fR refs\&. .RE .PP \fB\-\-sort=\fR\fI\fR .RS 4 Sort on the field name \fI\fR\&. Prefix \fB\-\fR to sort in descending order of the value\&. When unspecified, \fBrefname\fR is used\&. You may use the \fB\-\-sort=\fR\fI\fR option multiple times, in which case the last key becomes the primary key\&. .RE .PP \fB\-\-format\fR[\fB=\fR\fI\fR] .RS 4 A string that interpolates \fB%\fR(\fBfieldname\fR) from a ref being shown and the object it points at\&. In addition, the string literal \fB%%\fR renders as \fB%\fR and \fB%xx\fR \- where \fBxx\fR are hex digits \- renders as the character with hex code \fBxx\fR\&. For example, \fB%00\fR interpolates to \fB\e0\fR (\fINUL\fR), \fB%09\fR to \fB\et\fR (\fITAB\fR), and \fB%0a\fR to \fB\en\fR (\fILF\fR)\&. .RE .sp When unspecified, \fI\fR defaults to \fB%\fR(\fBobjectname\fR) \fBSPC\fR \fB%\fR(\fBobjecttype\fR) \fBTAB\fR \fB%\fR(\fBrefname\fR)\&. .PP \fB\-\-color\fR[\fB=\fR\fI\fR] .RS 4 Respect any colors specified in the \fB\-\-format\fR option\&. The \fI\fR field must be one of \fBalways\fR, \fBnever\fR, or \fBauto\fR (if \fI\fR is absent, behave as if \fBalways\fR was given)\&. .RE .PP \fB\-\-shell\fR, \fB\-\-perl\fR, \fB\-\-python\fR, \fB\-\-tcl\fR .RS 4 If given, strings that substitute \fB%\fR(\fBfieldname\fR) placeholders are quoted as string literals suitable for the specified host language\&. This is meant to produce a scriptlet that can directly be "eval"ed\&. .RE .PP \fB\-\-points\-at=\fR\fI\fR .RS 4 Only list refs which points at the given object\&. .RE .PP \fB\-\-merged\fR[\fB=\fR\fI\fR] .RS 4 Only list refs whose tips are reachable from the specified commit (\fBHEAD\fR if not specified)\&. .RE .PP \fB\-\-no\-merged\fR[\fB=\fR\fI\fR] .RS 4 Only list refs whose tips are not reachable from \fI\fR(\fBHEAD\fR if not specified)\&. .RE .PP \fB\-\-contains\fR[\fB=\fR\fI\fR] .RS 4 Only list refs which contain \fI\fR(\fBHEAD\fR if not specified)\&. .RE .PP \fB\-\-no\-contains\fR[\fB=\fR\fI\fR] .RS 4 Only list refs which don\(cqt contain \fI\fR (\fBHEAD\fR if not specified)\&. .RE .PP \fB\-\-ignore\-case\fR .RS 4 Sorting and filtering refs are case insensitive\&. .RE .PP \fB\-\-omit\-empty\fR .RS 4 Do not print a newline after formatted refs where the format expands to the empty string\&. .RE .PP \fB\-\-exclude=\fR\fI\fR .RS 4 If one or more \fB\-\-exclude\fR options are given, only refs which do not match any \fI\fR parameters are shown\&. Matching is done using the same rules as \fI\fR above\&. .RE .PP \fB\-\-include\-root\-refs\fR .RS 4 List root refs (\fBHEAD\fR and pseudorefs) apart from regular refs\&. .RE .PP \fB\-\-start\-after=\fR\fI\fR .RS 4 Allows paginating the output by skipping references up to and including the specified marker\&. When paging, it should be noted that references may be deleted, modified or added between invocations\&. Output will only yield those references which follow the marker lexicographically\&. Output begins from the first reference that would come after the marker alphabetically\&. Cannot be used with \fB\-\-sort=\fR\fI\fR or \fB\-\-stdin\fR options, or the \fI\fR argument(s) to limit the refs\&. .RE .SH "FIELD NAMES" .sp Various values from structured fields in referenced objects can be used to interpolate into the resulting output, or as sort keys\&. .sp For all objects, the following names can be used: .PP \fBrefname\fR .RS 4 The name of the ref (the part after \fB$GIT_DIR/\fR)\&. For a non\-ambiguous short name of the ref append \fB:short\fR\&. The option \fBcore\&.warnAmbiguousRefs\fR is used to select the strict abbreviation mode\&. If \fBlstrip=\fR\fI\fR (\fBrstrip=\fR\fI\fR) is appended, strip \fI\fR slash\-separated path components from the front (back) of the refname (e\&.g\&. \fB%\fR(\fBrefname:lstrip=2\fR) turns \fBrefs/tags/foo\fR into \fBfoo\fR and \fB%\fR(\fBrefname:rstrip=2\fR) turns \fBrefs/tags/foo\fR into \fBrefs\fR)\&. If \fI\fR is a negative number, strip as many path components as necessary from the specified end to leave \fB\-\fR\fI\fR path components (e\&.g\&. \fB%\fR(\fBrefname:lstrip=\-2\fR) turns \fBrefs/tags/foo\fR into \fBtags/foo\fR and \fB%\fR(\fBrefname:rstrip=\-1\fR) turns \fBrefs/tags/foo\fR into \fBrefs\fR)\&. When the ref does not have enough components, the result becomes an empty string if stripping with positive \fI\fR, or it becomes the full refname if stripping with negative \fI\fR\&. Neither is an error\&. .sp \fBstrip\fR can be used as a synonym to \fBlstrip\fR\&. .RE .PP \fBobjecttype\fR .RS 4 The type of the object (\fBblob\fR, \fBtree\fR, \fBcommit\fR, \fBtag\fR)\&. .RE .PP \fBobjectsize\fR .RS 4 The size of the object (the same as \fIgit cat\-file \-s\fR reports)\&. Append \fB:disk\fR to get the size, in bytes, that the object takes up on disk\&. See the note about on\-disk sizes in the \fICAVEATS\fR section below\&. .RE .PP \fBobjectname\fR .RS 4 The object name (aka SHA\-1)\&. For a non\-ambiguous abbreviation of the object name append \fB:short\fR\&. For an abbreviation of the object name with desired length append \fB:short=\fR\fI\fR, where the minimum length is \fBMINIMUM_ABBREV\fR\&. The length may be exceeded to ensure unique object names\&. .RE .PP \fBdeltabase\fR .RS 4 This expands to the object name of the delta base for the given object, if it is stored as a delta\&. Otherwise it expands to the null object name (all zeroes)\&. .RE .PP \fBupstream\fR .RS 4 The name of a local ref which can be considered \(lqupstream\(rq from the displayed ref\&. Respects \fB:short\fR, \fB:lstrip\fR and \fB:rstrip\fR in the same way as \fBrefname\fR above\&. Additionally respects \fB:track\fR to show "[ahead N, behind M]" and \fB:trackshort\fR to show the terse version: ">" (ahead), "<" (behind), "<>" (ahead and behind), or "=" (in sync)\&. \fB:track\fR also prints "[gone]" whenever unknown upstream ref is encountered\&. Append \fB:track\fR,nobracket to show tracking information without brackets (i\&.e "ahead N, behind M")\&. .sp For any remote\-tracking branch \fB%\fR(\fBupstream\fR), \fB%\fR(\fBupstream:remotename\fR) and \fB%\fR(\fBupstream:remoteref\fR) refer to the name of the remote and the name of the tracked remote ref, respectively\&. In other words, the remote\-tracking branch can be updated explicitly and individually by using the refspec \fB%\fR(\fBupstream:remoteref\fR)\fB:%\fR(\fBupstream\fR) to fetch from \fB%\fR(\fBupstream:remotename\fR)\&. .sp Has no effect if the ref does not have tracking information associated with it\&. All the options apart from \fBnobracket\fR are mutually exclusive, but if used together the last option is selected\&. .RE .PP \fBpush\fR .RS 4 The name of a local ref which represents the \fB@\fR{push} location for the displayed ref\&. Respects \fB:short\fR, \fB:lstrip\fR, \fB:rstrip\fR, \fB:track\fR, \fB:trackshort\fR, \fB:remotename\fR, and \fB:remoteref\fR options as \fBupstream\fR does\&. Produces an empty string if no \fB@\fR{push} ref is configured\&. .RE .PP \fBHEAD\fR .RS 4 \fB*\fR if \fBHEAD\fR matches current ref (the checked out branch), \*(Aq \*(Aq otherwise\&. .RE .PP \fBcolor\fR .RS 4 Change output color\&. Followed by \fB:\fR\fI\fR, where color names are described under Values in the "CONFIGURATION FILE" section of \fBgit-config\fR(1)\&. For example, \fB%\fR(\fBcolor:bold\fR \fBred\fR)\&. .RE .PP \fBalign\fR .RS 4 Left\-, middle\-, or right\-align the content between \fB%\fR(\fBalign:\fR\fB\&.\&.\&.\fR) and \fB%\fR(\fBend\fR)\&. The "\fBalign:\fR" is followed by \fBwidth=\fR\fI\fR and \fBposition=\fR\fI\fR in any order separated by a comma, where the \fI\fR is either \fBleft\fR, \fBright\fR or \fBmiddle\fR, default being \fBleft\fR and \fI\fR is the total length of the content with alignment\&. For brevity, the "width=" and/or "position=" prefixes may be omitted, and bare \fI\fR and \fI\fR used instead\&. For instance, \fB%\fR(\fBalign:\fR\fI\fR\fB,\fR\fI\fR)\&. If the contents length is more than the width then no alignment is performed\&. If used with \fB\-\-quote\fR everything in between \fB%\fR(\fBalign:\fR\fB\&.\&.\&.\fR) and \fB%\fR(\fBend\fR) is quoted, but if nested then only the topmost level performs quoting\&. .RE .PP \fBif\fR .RS 4 Used as \fB%\fR(\fBif\fR)\fB\&.\&.\&.\fR\fB%\fR(\fBthen\fR)\fB\&.\&.\&.\fR\fB%\fR(\fBend\fR) or \fB%\fR(\fBif\fR)\fB\&.\&.\&.\fR\fB%\fR(\fBthen\fR)\fB\&.\&.\&.\fR\fB%\fR(\fBelse\fR)\fB\&.\&.\&.\fR\fB%\fR(\fBend\fR)\&. If there is an atom with value or string literal after the \fB%\fR(\fBif\fR) then everything after the \fB%\fR(\fBthen\fR) is printed, else if the \fB%\fR(\fBelse\fR) atom is used, then everything after %(else) is printed\&. We ignore space when evaluating the string before \fB%\fR(\fBthen\fR), this is useful when we use the \fB%\fR(\fBHEAD\fR) atom which prints either "\fB*\fR" or " " and we want to apply the \fIif\fR condition only on the \fBHEAD\fR ref\&. Append "\fB:equals=\fR\fI\fR" or "\fB:notequals=\fR\fI\fR" to compare the value between the \fB%\fR(\fBif:\fR\fB\&.\&.\&.\fR) and \fB%\fR(\fBthen\fR) atoms with the given string\&. .RE .PP \fBsymref\fR .RS 4 The ref which the given symbolic ref refers to\&. If not a symbolic ref, nothing is printed\&. Respects the \fB:short\fR, \fB:lstrip\fR and \fB:rstrip\fR options in the same way as \fBrefname\fR above\&. .RE .PP \fBsignature\fR .RS 4 The GPG signature of a commit\&. .RE .PP \fBsignature:grade\fR .RS 4 Show .PP \fBG\fR .RS 4 for a good (valid) signature .RE .PP \fBB\fR .RS 4 for a bad signature .RE .PP \fBU\fR .RS 4 for a good signature with unknown validity .RE .PP \fBX\fR .RS 4 for a good signature that has expired .RE .PP \fBY\fR .RS 4 for a good signature made by an expired key .RE .PP \fBR\fR .RS 4 for a good signature made by a revoked key .RE .PP \fBE\fR .RS 4 if the signature cannot be checked (e\&.g\&. missing key) .RE .PP \fBN\fR .RS 4 for no signature\&. .RE .RE .PP \fBsignature:signer\fR .RS 4 The signer of the GPG signature of a commit\&. .RE .PP \fBsignature:key\fR .RS 4 The key of the GPG signature of a commit\&. .RE .PP \fBsignature:fingerprint\fR .RS 4 The fingerprint of the GPG signature of a commit\&. .RE .PP \fBsignature:primarykeyfingerprint\fR .RS 4 The primary key fingerprint of the GPG signature of a commit\&. .RE .PP \fBsignature:trustlevel\fR .RS 4 The trust level of the GPG signature of a commit\&. Possible outputs are \fBultimate\fR, \fBfully\fR, \fBmarginal\fR, \fBnever\fR and \fBundefined\fR\&. .RE .PP \fBworktreepath\fR .RS 4 The absolute path to the worktree in which the ref is checked out, if it is checked out in any linked worktree\&. Empty string otherwise\&. .RE .PP \fBahead\-behind:\fR\fI\fR .RS 4 Two integers, separated by a space, demonstrating the number of commits ahead and behind, respectively, when comparing the output ref to the \fI\fR specified in the format\&. .RE .PP \fBis\-base:\fR\fI\fR .RS 4 In at most one row, (\fI\fR) will appear to indicate the ref that is most likely the ref used as a starting point for the branch that produced \fI\fR\&. This choice is made using a heuristic: choose the ref that minimizes the number of commits in the first\-parent history of \fI\fR and not in the first\-parent history of the ref\&. .sp For example, consider the following figure of first\-parent histories of several refs: .sp .if n \{\ .RS 4 .\} .nf *\-\-*\-\-*\-\-*\-\-*\-\-* refs/heads/A \e \e *\-\-*\-\-*\-\-* refs/heads/B \e \e \e \e * * refs/heads/C \e \e *\-\-* refs/heads/D .fi .if n \{\ .RE .\} .sp Here, if \fBA\fR, \fBB\fR, and \fBC\fR are the filtered references, and the format string is \fB%\fR(\fBrefname\fR)\fB:%\fR(\fBis\-base:D\fR), then the output would be .sp .if n \{\ .RS 4 .\} .nf refs/heads/A: refs/heads/B:(D) refs/heads/C: .fi .if n \{\ .RE .\} .sp This is because the first\-parent history of \fBD\fR has its earliest intersection with the first\-parent histories of the filtered refs at a common first\-parent ancestor of \fBB\fR and \fBC\fR and ties are broken by the earliest ref in the sorted order\&. .sp Note that this token will not appear if the first\-parent history of \fI\fR does not intersect the first\-parent histories of the filtered refs\&. .RE .PP \fBdescribe\fR[\fB:\fR\fI