# Running commands against PR branches

**URL:** <https://discuss.circleci.com/t/running-commands-against-pr-branches/3330>\
**Category:** Build Environment\
**Tags:** git\
**Created:** [April 13, 2016, 9:07pm UTC](https://discuss.circleci.com/t/running-commands-against-pr-branches/3330 "2016-04-13T21:07:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Caerbannog](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/caerbannog/32/8664_2.png) [@Caerbannog](https://discuss.circleci.com/u/Caerbannog)\
**Post date:** [November 22, 2017, 9:16am UTC](https://discuss.circleci.com/t/running-commands-against-pr-branches/3330/2 "2017-11-22T09:16:24Z")

</div>

**[EDIT] This does not work for PRs containing multiple commits. CIRCLE\_COMPARE\_URL refers to diffs introduced by a single git push.**

You can follow this idea:

> [@Early success in a build](https://discuss.circleci.com/t/early-success-in-a-build/14461/2):
>
> The approach was to create a logical\_changes.sh which parses the git refs in CIRCLE\_COMPARE\_URL to determine the appropriate git diff ref1 ref2 --name-only command to run.

Here is a code example:

```
#CIRCLE_COMPARE_URL=https://github.com/dtprotel/protel360/compare/e8f67d33a268...1d340f4990b5
#Parsing this variable inside circle ci exports.

#Get Commit Ids Part
COMMIT_ID_PARTS=""
IFS='/'
splittedArray=$CIRCLE_COMPARE_URL
for x in $splittedArray
do
    COMMIT_ID_PARTS=$x
done
printf "> Build is between commits : $COMMIT_ID_PARTS\n"

```

(source [NameBright - Coming Soon](http://codegist.net/snippet/shell/circle_ci_deploysh_erdemolkun_shell))

---

_[View the full topic](https://discuss.circleci.com/t/running-commands-against-pr-branches/3330)._
