Jenkins Pipeline: is it possible to avoid multiple checkout?
<p>I've moved a few old Jenkins jobs to new ones using the <a href="https://jenkins.io/doc/pipeline/">pipeline feature</a> in order to be able to integrate the Jenkins configuration within the git repositories. 
It's working fine but I'm asking myself if there is a way to reduce the number of checkout that happens while building.</p>

<p><strong>Setup</strong></p>

<ul>
<li>I have a Jenkins multibranch job which is related to my git repository</li>
<li><p>I have a Jenkinsfile in my git repository</p>

<pre><code>#!groovy
node {

  stage 'Checkout'
  checkout scm

  // build project
  stage 'Build'
  ...
}
</code></pre></li>
</ul>

<p><strong>Problem</strong></p>

<p>When I push to my remote branche <em>BRANCH_1</em>, the multibranch jenkins job is triggered and my understanding is that the following steps happen:</p>

<ul>
<li>the multibranch job makes a <code>git fetch</code> for the branch indexing and triggers the job corresponding to my remote branch: <em>BRANCH_1_job</em></li>
<li><em>BRANCH_1_job</em> makes a <code>git checkout</code> to retrieve the Jenkinsfile of the triggered branch</li>
<li>the Jenkinsfile is executed and makes a <code>checkout scm</code> itself. If I don't do it, I can not build my project because no source are available.</li>
</ul>

<p>So for building my branch, I end up with one <code>git fetch</code> and two <code>git checkout</code>.</p>

<p><strong>Questions</strong></p>

<ul>
<li>Do I understand the process correctly? Or did I miss something?</li>
<li>Is there a way to reduce the number of <code>git checkout</code>? When I check the <a href="https://github.com/jenkinsci/pipeline-examples/tree/master/jenkinsfile-examples">official examples</a>, they all make a checkout scm as first step. I would personally think that I don't have to do it because the jenkins job already had to make a checkout to retrieve the Jenkinsfile (so my sources have to be here somehow).</li>
<li>Don't you think these multiple checkouts can cause bad performance as soon as the git repo contains a big number of refs?</li>
</ul>

<p>Thanks you all</p>