git rev-parse

A low-level command that turns a name such as HEAD, main or HEAD~1 into an object ID, and answers questions about the repository.

In more detail

git rev-parse HEAD prints the full ID of the current commit and --short abbreviates it. --show-toplevel prints the root folder of the repository you are in, and --show-prefix prints where you are relative to that root. Scripts use it to get exact answers instead of parsing other output.

Examples

git rev-parse --show-toplevel
git rev-parse main feature

Related terms

Taught in

References