title: Checkout part of a branch in Azure DevOps Pipelines (GetSources)
body: <p>My repository in my organisation's devops project contains a lot of .net solutions and some unity projects as well. When I run my build pipeline, it fails due to several of these:</p>
  
  <blockquote>
    <p>Error MSB3491: Could not write lines to file "obj\Release\path\to\file". There is not enough space on the disk.</p>
  </blockquote>
  
  <p>I would like the pipeline to only checkout and fetch parts of the repository that are required for a successful build. This might also help with execution time of the pipeline since it currently also fetches the whole of my unity projects with gigabytes of resources which takes forever.</p>
  
  <p>I would like to spread my projects across multiple repositories but the admin won't give me more than the one I already have. It got a lot better when I configured git fetch as shallow (<code>--depth=1</code>) but I still get the error every now and then.</p>
  
  <p>This is how I configured the checkout:</p>
  
  <pre><code>steps:
  - checkout: self
    clean: true
    # shallow fetch
    fetchDepth: 1
    lfs: false
    submodules: false
  </code></pre>
  
  <p>The build is done using <code>VSBuild@1</code> task.</p>
  
  <p>I can't find a valid solution to my problem except for using multiple repositories, which is not an option right now.</p>
  
  <p><strong>Edit: Shayki Abramczyk's solution #1 works perfectly. Here is my full implementation.</strong></p>
  
  <p><code>GitSparseCheckout.yml</code>:</p>
  
  <pre><code>parameters:
    access: ''
    repository: ''
    sourcePath: ''
  
  steps:
  - checkout: none
  
  - task: CmdLine@2
    inputs:
      script: |
        ECHO ##[command] git init
        git init
        ECHO ##[command] git sparse-checkout: ${{ parameters.sourcePath }}
        git config core.sparsecheckout true
        echo ${{ parameters.sourcePath }} &gt;&gt; .git/info/sparse-checkout
        ECHO ##[command] git remote add origin https://${{ parameters.repository }}
        git remote add origin https://${{ parameters.access }}@${{ parameters.repository }}
        ECHO ##[command] git fetch --progress --verbose --depth=1 origin master
        git fetch --progress --verbose --depth=1 origin master
        ECHO ##[command] git pull --progress --verbose origin master
        git pull --progress --verbose origin master
  </code></pre>
  
  <p>Checkout is called like this (where template path has to be adjusted):</p>
  
  <pre><code>- template: ../steps/GitSparseCheckout.yml
    parameters:
      access: anything:&lt;YOUR_PERSONAL_ACCESS_TOKEN&gt;
      repository: dev.azure.com/organisation/project/_git/repository
      sourcePath: path/to/files/
  </code></pre>