# Only build on specific branches and PRs

**URL:** <https://discuss.circleci.com/t/only-build-on-specific-branches-and-prs/29386>\
**Category:** Build Environment\
**Created:** [March 29, 2019, 9:49am UTC](https://discuss.circleci.com/t/only-build-on-specific-branches-and-prs/29386 "2019-03-29T09:49:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matthew-inamdar](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/matthew-inamdar/32/21830_2.png) [@matthew-inamdar](https://discuss.circleci.com/u/matthew-inamdar)\
**Post date:** [March 29, 2019, 9:49am UTC](https://discuss.circleci.com/t/only-build-on-specific-branches-and-prs/29386/1 "2019-03-29T09:49:27Z")

</div>

Hi there,

I’m using config version 2.1 and trying to achieve the following on steps:

1. Only build commits pushed to `master`
2. Only build commits pushed to `develop`
3. Only build pull requests

I can easily achieve the firs two using:

```auto
workflows:
  version: 2
  test-and-deploy:
    jobs:
      - test:
          filters:
            branches:
              only:
                - master
                - develop

```

However how can I add to the filters, to also build pull requests?

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 29, 2019, 11:08pm UTC](https://discuss.circleci.com/t/only-build-on-specific-branches-and-prs/29386/2 "2019-03-29T23:08:40Z")

</div>

PRs should be built by default - are they not being built with this config?

Are these PRs for the same user, in the same org, or in a fork?

---

<div class="post-metadata">

**Author:** ![matthew-inamdar](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/matthew-inamdar/32/21830_2.png) [@matthew-inamdar](https://discuss.circleci.com/u/matthew-inamdar)\
**Post date:** [March 30, 2019, 1:02pm UTC](https://discuss.circleci.com/t/only-build-on-specific-branches-and-prs/29386/3 "2019-03-30T13:02:58Z")

</div>

Nope, not being built. Only commits pushed to `master` and `develop`. I’m following Git Flow, so all PR’s are based off of `master` or `develop`.

I read on one of the other posts, to try adding `/^(?!pull\/).*$/`, however this caused commits in every single branch to be built.

---

<div class="post-metadata">

**Author:** ![halfer](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/halfer/32/9083_2.png) [@halfer](https://discuss.circleci.com/u/halfer)\
**Post date:** [March 30, 2019, 5:32pm UTC](https://discuss.circleci.com/t/only-build-on-specific-branches-and-prs/29386/4 "2019-03-30T17:32:41Z")

</div>

> [@matthew-inamdar](#):
>
> to try adding `/^(?!pull\/).*$/` ,

Do you mean as a branch name filter? I am unfamiliar with how PRs are presented to Git inside the PR process - do they always get this as a prefix? If this _is_ a branch name, then I wonder whether you would need an ignore rule as well - this is rather non-intuitive, but the docs do try to cover it.

See my [demo here](https://github.com/halfer/cd-demo-container/blob/master/.circleci/config.yml), particularly the `only-deploy-tags` section (and where that is injected into the `workflows` section).
