# Checkout script adds commits to master from $CIRCLE\_BRANCH

**URL:** <https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194>\
**Category:** Bug Reports\
**Created:** [July 12, 2017, 4:14pm UTC](https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194 "2017-07-12T16:14:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![leifg](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/leifg/32/2431_2.png) [@leifg](https://discuss.circleci.com/u/leifg)\
**Post date:** [July 12, 2017, 4:14pm UTC](https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194/1 "2017-07-12T16:14:46Z")

</div>

I noticed that the output of `git merge-base master HEAD` was different on my local system than the CI system.

After some digging around I found something strange.

The commits on `master` and `$CIRCLE_BRANCH` are exactly the same (which should not be the case as the feature branch is ahead of master when opening a pull request).

This can easily be verified by running the log command

`git log -n1 master` has the exact same output as ``git log -n1 $CIRCLE\_BRANCH`

This leads to problems when running tools that compare changes to the master branch. (such as [pronto](https://github.com/prontolabs/pronto)).

The workaround is a hard reset on master:

```auto
git checkout master
git reset --hard origin/master
git checkout -

```

---

<div class="post-metadata">

**Author:** ![rishimkumar](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/rishimkumar/32/4798_2.png) [@rishimkumar](https://discuss.circleci.com/u/rishimkumar)\
**Post date:** [July 12, 2017, 4:39pm UTC](https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194/2 "2017-07-12T16:39:12Z")

</div>

If I understand correctly,

We optimize checkout significantly and only guarantee that the current branch checkout matches the branch that should be built.

you could run `git fetch && git merge-base origin/master HEAD` to get your desired behavior

thanks!  
RK

---

<div class="post-metadata">

**Author:** ![leifg](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/leifg/32/2431_2.png) [@leifg](https://discuss.circleci.com/u/leifg)\
**Post date:** [July 13, 2017, 7:47am UTC](https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194/3 "2017-07-13T07:47:00Z")

</div>

That’s a good workaround as well. Luckily my tool allows injecting custom commit for merge-base. I don’t know how other tools handle this but it still feels wrong to have master and $CIRCLE\_BRANCH including the same content.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [June 18, 2018, 11:34am UTC](https://discuss.circleci.com/t/checkout-script-adds-commits-to-master-from-circle-branch/14194/4 "2018-06-18T11:34:52Z")

</div>

Please see: [Git checkout of a branch destroys local reference to master - #16 by pete-woods](https://discuss.circleci.com/t/git-checkout-of-a-branch-destroys-local-reference-to-master/23781/16)
