Git rev-list within ci

I’m building a ReactJS application via cicd.

Previously I was building locally and I have a script that injects the current build version into the index.html after the project is built. I did this by using git rev-list --count --first-parent for both the master and dev branches ( version MASTER.DEV eg 2.27 )

The only way I can think of doing something similar is cloning my project to the cicd environment as part of my yaml job which seems like overkill. This is all done through gitlab ci which has access to my git repo but I’m thinking ci variables like $CI_MASTER_BRANCH_REVISION are out of the question as that is a bit silly.

What can I do?