Execute a job on a specific branch in GitLab

For example - we want that the job should be executed only on master branch when a merge occur.
We need a condition what will check if we are in the master branch. This can be done using rules.
Use rules to include or exclude jobs in pipelines.

Example:

deploy to s3:
    image:
        name: amazon/aws-cli
        entrypoint: [""]
    script:
        - aws --version
        - aws s3 sync build s3://$AWS_S3_BUCKET --delete
    rules:
        - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
Where: CI_COMMIT_REF_NAME - The branch or tag name for which project is built
CI_DEFAULT_BRANCH - The name of the project’s default branch

As a result - this job will be executed only on master branch