This line requires the git executable to be installed. Our Dockerfiles are optimised to not have unnecessary things such as git installed, which means although the .git directory is there, this workflow fails for us.
Rather than relying on a binary, it might be a nicer option to read directly from the files that git itself reads from, which (I haven't checked, but I presume) are .git/HEAD and then whatever that points to (e.g. .git/refs/heads/main for our deployed app).
Here's an example of the config I'm trying out at Exercism for this: https://github.com/exercism/website/pull/1069/files
If we changed this upstream in this repo I could remove that messiness :)