It will clone the whole repository content even you add .gitignore.
You could customize the checkout step via Command line task with "git sparse-checkout".
Sample as below:
trigger: none
pool:
vmImage: ubuntu-latest
steps:
- checkout: none
- script: |
git init $(System.TeamProject) && cd $(System.TeamProject)
git config core.sparsecheckout true
echo '/*' >> .git/info/sparse-checkout
echo '!testfolder2/*' >> .git/info/sparse-checkout
git remote add origin https://anything:$(PAT)@dev.azure.com/{yourorg}/{yourproject}/_git/{yourrepo}
git pull origin main
git checkout main && ls

You can find similar link here and here.