I have a project in Azure DevOps. I want to copy a particular file from the project's Git Repository to my unix box. I want to achieve this using command line.
I tried the below command
wget -O /unix/path/to/save/file.txt "https://tfs-glo-org.visualstudio.com/team/_git/projectName?path=/fileTobeCopied&version=GBbranch"
It successfully copies a file to the unix box but instead of just the file that I want, it saves a whole html page.
This is no easy feat. The raw download url is a bit more complex:
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}
/items?path={path}&scopePath={scopePath}&recursionLevel={recursionLevel}
&includeContentMetadata={includeContentMetadata}&latestProcessedChange={latestProcessedChange}
&download={download}&$format={$format}&versionDescriptor.versionOptions={versionDescriptor.versionOptions}
&versionDescriptor.version={versionDescriptor.version}&versionDescriptor.versionType={versionDescriptor.versionType}
&includeContent={includeContent}&resolveLfs={resolveLfs}&api-version=5.1
The most important thing for you here is to set &download=true. Easiest way ti get these values is to download a file from the UI and inspect the download url:

You can get the full url from the Downloads page in your browser:

The full docs for the request format can be found here.
In order for the download to succeed you'll also need to pass in an authentication token or Personal access token. The security parts are explained here.
The easiest option would be to use a Personal Access Token:
wget --user . --password {PAT} https://dev.azure.com/....
If the credentials aren't passed in, Azure DevOps will send the error page contents instead.
Files are stored in Git Source control for a reason. Not to be downloaded the way that you are trying to do.
Using the command line git clone the repository and find the file that you want to pick.
https://www.atlassian.com/git/tutorials/setting-up-a-repository/git-clone
You can always target a specific tag or a commit.
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