Turn HEAD~3 / origin/main / :/typo / etc. into a SHA.
git rev-parse turns any revision spec - HEAD~3, origin/main, :/typo, v1.0^{commit} - into a concrete SHA. It also exposes repo layout facts.
Two jobs in one binary: (1) resolve names to OIDs, (2) answer 'where am I?' questions about the current repo. Every shell-script-flavored Git tool calls it.
git rev-parse [<options>] <args>...
git rev-parse HEAD # full SHA of HEAD
git rev-parse --short=8 HEAD # 8-char abbreviation
git rev-parse --abbrev-ref HEAD # 'main' instead of refs/heads/main
git rev-parse --show-toplevel # absolute path to repo root
git rev-parse --is-inside-work-tree # 'true' or 'false'
| Flag | What it does |
|---|---|
<args> | Revision specs or option flags to resolve |
--verify | Require args to resolve to exactly one object; exit nonzero otherwise |
--short[=<n>] | Abbreviate output SHAs to the shortest unique prefix (or n chars) |
--symbolic | Print the input symbolic name when it is one |
--symbolic-full-name | Expand to full ref name (refs/heads/main) |
--abbrev-ref[=<mode>] | Shorten to short ref name (main, origin/main) |
--git-dir | Print the path to the .git directory |
--show-toplevel | Print the absolute path to the working-tree root |
--is-inside-work-tree | Print true/false: are we inside a working tree |
--is-bare-repository | Print true/false: is this a bare repo |
--git-common-dir | Print the common .git dir (matters for worktrees) |
git rev-parse HEADgit rev-parse --verify --quiet refs/heads/featureROOT=$(git rev-parse --show-toplevel)git rev-parse --abbrev-ref HEADHit each option, then Check answers. Score is recorded; Next is always open.