git-check-ref-format

Validate and normalize Git reference names

TLDR

Check if ref name is valid
$ git check-ref-format [refs/heads/branch]
Check branch name
$ git check-ref-format --branch [name]
Normalize refname
$ git check-ref-format --normalize [refs/heads/branch]

SYNOPSIS

git check-ref-format [options] refname

DESCRIPTION

git check-ref-format validates and normalizes Git reference names according to strict naming rules. This ensures branch and tag names are portable across filesystems and don't conflict with Git internals.Reference names must not contain spaces, tildes, carets, colons, question marks, asterisks, or brackets. They cannot begin or end with slashes, contain consecutive slashes, or end with .lock. Components between slashes cannot begin with dots. These rules prevent filesystem conflicts and shell interpretation issues.The command is used programmatically by scripts creating branches or tags to validate user input before attempting operations. Normalization removes redundant slashes and ensures consistent formatting. The --branch option interprets the name as a branch shorthand, expanding it to refs/heads/ format.

PARAMETERS

--branch

Check as branch name.
--normalize
Normalize refname.
--allow-onelevel
Allow single-level refs (refnames without multiple `/`-separated components).
--no-allow-onelevel
Require hierarchical refs (default).
--refspec-pattern
Interpret refname as a refspec pattern, allowing a single `*` wildcard.

INSTALL

sudo apt install git
sudo dnf install git
sudo pacman -S git
sudo apk add git
sudo zypper install git
brew install git
nix profile install nixpkgs#git

SEE ALSO

git-branch(1), git-tag(1)