Changing Git branches causes commits from one branch to carry over to the next

I am triggering nightly builds with the CircleCI API.

I have a problem where I check out a branch, such as staging. I do some work on that branch, and create a pull request using the github api.

I then check out another branch, and I get the following strangeness:

Switched to branch 'develop'
Your branch is ahead of 'origin/develop' by 146 commits.
  (use "git push" to publish your local commits)

I have to run git reset --hard origin/develop to get rid of those 146 commits. Those commits, upon inspection through SSHing into the terminal, are actually from the staging branch. Changing to develop changes the branch that I’m working with as far as git is concerned, but the commits involved aren’t correct and must be manually reset.

I cannot replicate this on a local environment. Is there something about the way circle CI handles git that I am unaware of?

This might be due to CircleCI doing shallowing clones during the checkout step rather than your typical git clone.