It's quite crude, since all I needed was the current branch name and the hash. git internally does a bunch of cache warming and verification that make it slower, so I just don't do that. The code is in my dotfiles[1].
I've been meaning to update it to include more information but I really don't want to have to touch packfiles in shell.
[1]: https://github.com/cyphar/dotfiles/blob/acbd9096a1daead80ba5...