Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git partial/sparse/narrow fetch and update in Azure Devops Hosted Agent

I am wondering if it's possible to fetch only a single file from a Git repository in order to commit a new change to it. We want to change the file on a Azure DevOps Hosted Agent however downloading the entire repo would take a significantly long time, as it is large.

I read of these options:

  1. --Filter option
  2. Git sparse checkout (I'm not sure if this is only available on GitHub)
  3. Microsoft GVFS

Filter command attempt

git clone --depth 1 --filter=sparse:path=ReadMe.md
warning: filtering not recognized by server, ignoring

Sparse checkout

git config core.sparsecheckout true
echo File.txt >> .git/info/sparse-checkout git pull origin master
However it still retrieved everything.

The server repository is running GIT v2.18.

  • Is there anything that needs to be configured on the server to make it these work?
  • Is the --filter option only available on certain versions?
  • Could GVFS achieve this and is it possible to setup on the Hosted Agent?

Thank you.

like image 605
user3167162 Avatar asked Sep 10 '25 21:09

user3167162


1 Answers

The best way to download one file from Git repo is with Azure DevOps Rest API - Items - Get.

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/items?path={path}&api-version=5.0-preview.1

If you add the parameter download (for example: ?path={path}&download=true) the file will be downloaded on the agent.

So add a task with a simple PowerShell script (with Invoke-RestMethod) and get the file.

like image 173
Shayki Abramczyk Avatar answered Sep 13 '25 11:09

Shayki Abramczyk