如何在Azure DevOps中使用Git LFS并将其集成至Azure Pipeline?
Absolutely, you can use Git LFS with Azure DevOps Repos—it’s natively supported, so you don’t have to set up any extra backend services. Let’s walk through how to get it working for your 5GB file, plus how to integrate it with Azure Pipelines.
1. Setting Up Git LFS in Your Azure DevOps Repo
Here’s how to configure Git LFS locally and push your large file to the repo:
- First, install Git LFS on your local machine if you haven’t already. Run this terminal command to initialize it:
git lfs install - Next, tell Git LFS to track your 5GB file. Replace
your-large-file.extwith your actual filename (you can also use wildcards like*.isoif you need to track multiple large files of the same type):git lfs track "your-large-file.ext" - This creates or updates a
.gitattributesfile, which Git uses to know which files to handle via LFS. Add this file to your repo and commit the change:git add .gitattributes git commit -m "Configure Git LFS for 5GB large file" - Finally, push your files to Azure DevOps. Git will automatically upload the large file to Azure’s dedicated LFS storage instead of storing it directly in the repo:
Azure DevOps handles the LFS storage backend automatically—no extra setup required here.git push origin main
2. Integrating Git LFS with Azure Pipelines
Getting Git LFS working in your pipeline is simple, and you have options depending on whether you use YAML or the classic pipeline editor:
Using YAML Pipelines
Add a checkout step with the lfs: true flag to ensure the pipeline pulls down your LFS files during the checkout process:
trigger: - main pool: vmImage: 'ubuntu-latest' # Swap for windows-latest or macos-latest if needed steps: - checkout: self lfs: true # Optional: If you only need your specific 5GB file, add a script to fetch just that file to save bandwidth - script: | # Example: Verify the LFS file was pulled git lfs ls-files # Perform your desired action, like uncompressing the file unzip your-large-file.zip displayName: 'Process large LFS file'
Using Classic Pipelines
- Edit your classic pipeline and navigate to the Get sources section.
- Under the Git LFS section, check the box labeled Enable Git LFS.
- Save and run your pipeline—it will now pull LFS files alongside your regular code automatically.
Extra Tips for Smooth Usage
- Self-hosted agents: If you’re using a self-hosted agent instead of Azure’s managed ones, make sure Git LFS is installed on the agent machine. Run
git lfs installonce to initialize it for future pipeline runs. - Optimize bandwidth: If you don’t need all tracked LFS files in your pipeline, use
git lfs fetch --include="your-large-file.ext"in a script step to only pull the specific file you need, which saves time and bandwidth. - Check storage quotas: LFS storage counts against your Azure DevOps organization’s storage quota. You can view your current usage in the organization settings under Billing.
内容的提问来源于stack exchange,提问作者sns
相关产品推荐
相关产品推荐

