Tip for Git Merge Operations in Azure DevOps Pipelines: Disable Shallow Fetch
Azure DevOps pipelines have a self-checkout feature when running a step in a pipeline which automatically runs git checkout
on the repository you’re running against. This generally works fine, however you may experience errors when trying to perform operations such as git merge
which aren’t reproducible locally.
The errors I experienced were when running --ff-only
merges
fatal: refusing to merge unrelated histories
If you supply --allow-unrelated-histories
, then git
errors out with
fatal: Not possible to fast-forward, aborting.
To resolve this, I set fetchDepth
to 0
in the checkout
step which ensured all commits were fetched and git
could perform the merge operation.
The relevant documentation on shallow fetching is available at https://learn.microsoft.com/en-us/azure/devops/pipelines/yaml-schema/steps-checkout?view=azure-pipelines#shallow-fetch