Checkout is wonky and is preventing a monorepo style repo here

We have our CI setup so no one can check into master and only branches named submit_xxxx/xxx are picked up by CI. Once we push a brach, we simply need git clone, and then git checkout remoteBranch BUT instead the state of the checked out work is that master is already corrupted and is 4 commits ahead of remote master. This is not good as we are trying to grab the hash using git commands.

In fact, right after the circleCI checks out master, we switch to master since we want to do a git merge --squash so we can squash ALL developer commits into one single commit. We do git checkout master to find out ALL the commits are there already???

#!/bin/bash -eo pipefail
git checkout master
Switched to branch ‘master’
Your branch is ahead of ‘origin/master’ by 4 commits.
(use “git push” to publish your local commits)
CircleCI received exit code 0

This is frustrating. the state of the repo is odd. How to fix this?