Forum Discussion
Is there any way to checkout a specific part of a Azure branch
We are committing our code to Azure Repos and building artifacts using Azure Classic Build Pipelines. But During the Checkout, it is downloading the entire repository and consuming lots of space and time.
Is there any way to checkout a specific part of a branch that includes only the required build files.
4 Replies
Please try to insert like below:
steps:
- checkout: self
path: path/yourfolder (Actual path to check out)- balasubramanimIron Contributor
You can’t directly check out only part of a repository in Azure Repos, but here are a few ways to reduce the space and time used during checkout:
Sparse Checkout (Manual):
Use a script to check out only specific folders.git init
git remote add origin https://{repo-url}.git
git config core.sparseCheckout true
echo "path/to/folder" >> .git/info/sparse-checkout
git pull origin {branch-name}Shallow Clone:
Only fetch the latest commit, reducing the data pulled
steps:
- checkout: self
fetchDepth:Separate Repo:
Split the important build files into a smaller, separate repository if possibleUse Artifacts:
Skip checkout and use pre-built artifacts from another pipeline to get only the files you need.These methods can help speed up your pipeline and reduce space usage.
- Rajesh_SwamyCopper Contributor
We tried with the sparsecheckout method, but its downloading entire branch instead of particular folder. Once please refer the attached the screenshot.
- balasubramanimIron Contributor
From the screenshot, it looks like the entire repository is being downloaded instead of just the specific folder.
This might happen due to one of the following reasons:
- Default Checkout Behavior: If you don’t explicitly disable the default checkout (checkout: none), Azure Pipelines will still download the entire repository.
- Sparse Checkout Configuration Issue: If there’s an issue in the configuration of the sparse checkout, it can cause the entire repository to be fetched.Please try the below steps to troubleshoot.
1. Disable Default Checkout: Ensure that you have disabled the default checkout of the entire repository at the beginning of your pipeline.
- checkout: none # Skip the default checkout2. Configure Sparse Checkout Properly: After disabling the default checkout, use a script to configure sparse checkout.
- script:
git init
git remote add origin <REPO_URL>
git config core.sparseCheckout true
echo "<folder_or_file_pattern>" >> .git/info/sparse-checkout
git fetch origin <branch_name>
git checkout <branch_name>
displayName: "Sparse Checkout Specific Files"Replace <REPO_URL>: Use the URL of your repository.
Replace <folder_or_file_pattern>: Specify the folder or file pattern you want to checkout. For example, src/ to only download the src folder.
Replace <branch_name>: Mention the branch name you’re trying to fetch3. Check Git Version on Agent: Make sure that the agent is using Git version 2.25 or later, as older versions might not fully support sparse checkouts.
- script: git --version
displayName: "Check Git Version"4. Use Fetch Depth (Optional): If you only need the latest commit, you can also limit the depth of the fetch operation, which reduces the amount of data transferred.
- script: |
git fetch --depth=1 origin <branch_name>
git checkout <branch_name>
displayName: "Shallow Fetch for Sparse Checkout"5. Verify Configuration: If the setup above still fetches the entire repository, check for any additional configurations or constraints set by your organization’s Azure DevOps setup that might override the sparse checkout commands.