Jenkins declarative pipeline: use branch if it exist
There's a resolveScm step implemented by the Pipeline: Multibranch plugin:
checkout resolveScm(source: [$class: 'GitSCMSource',
                             credentialsId: '&lt;credentialsId&gt;',
                             id: '_',
                             remote: 'https://your.git.remote/repository.git',
                             traits: [[$class: 'jenkins.plugins.git.traits.BranchDiscoveryTrait']]],
                    targets: [BRANCH_NAME, 'master'])

Above procedure will look whether $BRANCH_NAME exists, check it out if yes and check out master otherwise.