We've got an issue where the Get Sources step on our builds is taking very large time to clone the repository on Agent for the first time however second time taking less time.
So is there a way to optimize Get Sources step so that it should not clone the whole history instead the last commit history.
Below is the example what we need to do in Get Sources step:
1. Master Branch
git clone --depth 1 <Repo Url>
2. Feature Branch
cd <Project Name>
git remote set-branches origin %remote_branch_name%
git fetch --depth 1 origin %remote_branch_name%
git checkout %remote_branch_name%
You can configure the --depth 1 also in Azure DevOps.
If you use .yaml pipeline:
steps:
- checkout: self
fetchDepth: 1
In the classic editor (in the "Get Sources" option):

Then you can add a command line task that do the cd and the other commands.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With